Skip to content

Build your personal knowledge base with Trilium Notes

feat(clipper): show the published date beside the description

Elian Doran888b5b2a3f92
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html
index db98c6aeca..17cfd697ba 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html
@@ -39,8 +39,9 @@
<li><em>Selection</em>, when text is selected on the page: <em>Save selection</em> saves
it into the note of that page's clippings, as the context menu does.</li>
<li><em>Page</em>, when the page has an article: <em>Save page to Trilium</em> saves
- the article's text and images, and the publication date shows next to the
- website when the page states one.</li>
+ the article's text and images. When the page states a publication date,
+ it shows under the description, marked by the <span class="tn-icon bx bx-calendar"></span> icon,
+ and is saved in the <code>#publishedDate</code> label of the note.</li>
<li><em>Bookmark</em>, always: a text box for a note about the page replaces
the preview, and <em>Save bookmark</em> (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>)
saves a link to the page with that note. Left empty, the title stays the
diff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsx
index 0c6a1aa0a2..1559c6d5ee 100644
--- a/apps/web-clipper/entrypoints/popup/main.tsx
+++ b/apps/web-clipper/entrypoints/popup/main.tsx
@@ -5,6 +5,7 @@ import type { IconData, IconDefinition, IconPack } from "@boxicons/js";
import AlignLeft from "@boxicons/js/icons/AlignLeft";
import Article from "@boxicons/js/icons/Article";
import Bookmark from "@boxicons/js/icons/Bookmark";
+import Calendar from "@boxicons/js/icons/Calendar";
import Cog from "@boxicons/js/icons/Cog";
import Crop from "@boxicons/js/icons/Crop";
import Globe from "@boxicons/js/icons/Globe";
@@ -404,11 +405,7 @@ function PagePreview({ tab, disabled, shortcuts, draft, onDraftChange }: {
onInput={(e) => onDraftChange({ ...draft, title: e.currentTarget.value })}
onKeyDown={saveNoteOnCtrlEnter}
/>
- {pageUrl && (
- <div className="page-meta">
- {new URL(pageUrl).hostname}{published && ` · Published ${published}`}
- </div>
- )}
+ {pageUrl && <div className="page-meta">{new URL(pageUrl).hostname}</div>}
</div>
</div>
)}
@@ -429,22 +426,35 @@ function PagePreview({ tab, disabled, shortcuts, draft, onDraftChange }: {
<div className="page-body">
{mode && (
- <div className="page-description-row">
- <span
- className="page-description-icon"
- title="The page's description. It is saved in the #pageDescription label of the note."
- >
- <Icon icon={AlignLeft} />
- </span>
- <textarea
- className="page-description"
- aria-label="Page description"
- placeholder="Add a description"
- rows={2}
- value={shownDescription}
- onInput={(e) => onDraftChange({ ...draft, description: e.currentTarget.value })}
- onKeyDown={saveNoteOnCtrlEnter}
- />
+ <div className="page-fields">
+ <div className="page-field">
+ <span
+ className="page-field-icon"
+ title="The page's description. It is saved in the #pageDescription label of the note."
+ >
+ <Icon icon={AlignLeft} />
+ </span>
+ <textarea
+ className="page-description"
+ aria-label="Page description"
+ placeholder="Add a description"
+ rows={2}
+ value={shownDescription}
+ onInput={(e) => onDraftChange({ ...draft, description: e.currentTarget.value })}
+ onKeyDown={saveNoteOnCtrlEnter}
+ />
+ </div>
+ {published && (
+ <div className="page-field">
+ <span
+ className="page-field-icon"
+ title="The date the page was published. It is saved in the #publishedDate label of the note."
+ >
+ <Icon icon={Calendar} />
+ </span>
+ <span className="page-date">Published {published}</span>
+ </div>
+ )}
</div>
)}
{mode === "note" && (
diff --git a/apps/web-clipper/entrypoints/popup/popup.css b/apps/web-clipper/entrypoints/popup/popup.css
index 05f7c30eef..d8a381969f 100644
--- a/apps/web-clipper/entrypoints/popup/popup.css
+++ b/apps/web-clipper/entrypoints/popup/popup.css
@@ -149,16 +149,19 @@ body {
}
}
- .page-description-row {
- display: flex;
+ .page-fields {
flex: none;
- align-items: flex-start;
- gap: 4px;
padding: 6px 8px 6px 6px;
border-bottom: 1px solid var(--main-border-color);
}
- .page-description-icon {
+ .page-field {
+ display: flex;
+ align-items: flex-start;
+ gap: 4px;
+ }
+
+ .page-field-icon {
display: flex;
flex: none;
padding: 3px 2px;
@@ -191,6 +194,13 @@ body {
}
}
+ .page-date {
+ padding: 4px 6px;
+ color: var(--muted-text-color);
+ font-size: 0.85em;
+ line-height: 1.3;
+ }
+
.page-content {
display: block;
flex: none;
diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsx
index 6c8768bc96..249b63e6cd 100644
--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx
+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx
@@ -215,12 +215,17 @@ describe("popup", () => {
expect(heading).not.toBeNull();
expect(heading?.querySelector(".page-icon svg path")).not.toBeNull();
expect(heading?.querySelector<HTMLInputElement>(".page-title")?.value).toBe("An article");
- expect(heading?.querySelector(".page-meta")?.textContent).toBe("example.com · Published 2024-05-01");
+ expect(heading?.querySelector(".page-meta")?.textContent).toBe("example.com");
+ expect(publishedDate()).toBe("Published 2024-05-01");
+ const dateIcon = container.querySelector<HTMLElement>(".page-fields > .page-field:nth-child(2) > .page-field-icon");
+ expect(dateIcon?.querySelector("svg.icon path")).not.toBeNull();
+ expect(dateIcon?.title).toBe(
+ "The date the page was published. It is saved in the #publishedDate label of the note.");
const frame = container.querySelector<HTMLIFrameElement>(".page-body iframe.page-content");
expect(frame?.getAttribute("sandbox")).toBe("allow-same-origin");
expect(frame?.getAttribute("srcdoc")).toBe(previewDocument(PAGE));
expect([ ...container.querySelector(".page-body")?.children ?? [] ].map((part) => part.className))
- .toEqual([ "page-description-row", "page-content" ]);
+ .toEqual([ "page-fields", "page-content" ]);
expect(button("Save page to Trilium")?.disabled).toBe(false);
});
@@ -239,6 +244,8 @@ describe("popup", () => {
executeScript.mockResolvedValueOnce([ { result: { ...PAGE, labels: {} } } ]);
await rerender();
expect(container.querySelector(".page-meta")?.textContent).toBe("example.com");
+ expect(container.querySelectorAll(".page-fields > .page-field")).toHaveLength(1);
+ expect(publishedDate()).toBeUndefined();
});
it("says so while the page is read", async () => {
@@ -295,11 +302,12 @@ describe("popup", () => {
expect(frameDocument()).toBe(previewDocument(SELECTION));
expect(shortcutOf("Save selection").keys).toEqual([ "Ctrl", "Shift", "S" ]);
expect(container.querySelector(".page-meta")?.textContent).toBe("example.com");
+ expect(publishedDate()).toBeUndefined();
await click("Page");
expect(modes()).toEqual([ [ "Selection", "false" ], [ "Page", "true" ], [ "Bookmark", "false" ] ]);
expect(frameDocument()).toBe(previewDocument(PAGE));
- expect(container.querySelector(".page-meta")?.textContent).toBe("example.com · Published 2024-05-01");
+ expect(publishedDate()).toBe("Published 2024-05-01");
await click("Save page to Trilium");
expect(sendMessage).toHaveBeenLastCalledWith({ name: "save-whole-page", page: PAGE });
@@ -356,6 +364,7 @@ describe("popup", () => {
expect(container.querySelector(".page-body iframe")).toBeNull();
expect(container.querySelector<HTMLInputElement>(".page-title")?.value).toBe("An article");
expect(container.querySelector(".page-meta")?.textContent).toBe("example.com");
+ expect(publishedDate()).toBeUndefined();
expect(shortcutOf("Save bookmark")).toEqual({ text: "Ctrl+Enter", keys: [ "Ctrl", "Enter" ] });
await type(".page-body .note-text", "Worth a read");
@@ -380,11 +389,11 @@ describe("popup", () => {
selection = SELECTION;
await rerender();
const description = () =>
- container.querySelector<HTMLTextAreaElement>(".page-body > .page-description-row .page-description");
+ container.querySelector<HTMLTextAreaElement>(".page-body > .page-fields .page-description");
expect(description()?.value).toBe("All about the post");
expect(description()?.getAttribute("aria-label")).toBe("Page description");
expect(description()?.getAttribute("placeholder")).toBe("Add a description");
- const icon = container.querySelector<HTMLElement>(".page-description-row .page-description-icon");
+ const icon = container.querySelector<HTMLElement>(".page-fields > .page-field:first-child > .page-field-icon");
expect(icon?.querySelector("svg.icon path")).not.toBeNull();
expect(icon?.title).toBe(
"The page's description. It is saved in the #pageDescription label of the note.");
@@ -767,3 +776,7 @@ function status() {
text: container.querySelector(".connection > span")?.textContent
};
}
+
+function publishedDate() {
+ return container.querySelector(".page-fields .page-date")?.textContent;
+}
diff --git a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
index 746e6e0274..2604c64d13 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
@@ -32,7 +32,7 @@ Clicking the extension's button in the browser toolbar opens its popup:
* The popup shows what will be saved from the current page: the note's title, which can be edited before saving, the website, and below them a preview, which starts with the page's description. A switch above the preview chooses what to save, among what the page offers:
* _Selection_, when text is selected on the page: _Save selection_ saves it into the note of that page's clippings, as the context menu does.
- * _Page_, when the page has an article: _Save page to Trilium_ saves the article's text and images, and the publication date shows next to the website when the page states one.
+ * _Page_, when the page has an article: _Save page to Trilium_ saves the article's text and images. When the page states a publication date, it shows under the description, marked by the <span class="tn-icon bx bx-calendar"></span> icon, and is saved in the `#publishedDate` label of the note.
* _Bookmark_, always: a text box for a note about the page replaces the preview, and _Save bookmark_ (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>) saves a link to the page with that note. Left empty, the title stays the page's title.
The description, marked by the <span class="tn-icon bx bx-align-left"></span> icon, comes from the page's `description` meta tag, or the one it gives social sites. It can be edited or cleared before saving, or written in when the page has none, and is saved in the `#pageDescription` label of the note. Clippings saved with the keyboard shortcuts or the context menu, screenshots and images included, get the description as the page gives it. Each clipping that brings a description updates the label.