Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(clipper): show the modified date as a field of its own
Elian Doranbfaa550eb0ad
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.htmlindex 17cfd697ba..f605878b84 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,9 +39,11 @@<li><em>Selection</em>, when text is selected on the page: <em>Save selection</em> savesit 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. 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>+ the article's text and images. When the page states when it was published,+ that date 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. When it+ states when it was last modified, that date shows below, marked by the <span+ class="tn-icon bx bx-history"></span> icon, and is saved in the <code>#modifiedDate</code> label.</li><li><em>Bookmark</em>, always: a text box for a note about the page replacesthe 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 thediff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsxindex 1559c6d5ee..823731baa5 100644--- a/apps/web-clipper/entrypoints/popup/main.tsx+++ b/apps/web-clipper/entrypoints/popup/main.tsx@@ -11,6 +11,7 @@ import Crop from "@boxicons/js/icons/Crop";import Globe from "@boxicons/js/icons/Globe";import HelpCircle from "@boxicons/js/icons/HelpCircle";import Highlight from "@boxicons/js/icons/Highlight";+import History from "@boxicons/js/icons/History";import Lock from "@boxicons/js/icons/Lock";import RefreshCw from "@boxicons/js/icons/RefreshCw";import Screenshot from "@boxicons/js/icons/Screenshot";@@ -387,7 +388,9 @@ function PagePreview({ tab, disabled, shortcuts, draft, onDraftChange }: {}const pageUrl = mode === "note" ? tab?.url : clip?.pageUrl;- const published = mode === "page" ? article?.labels.publishedDate : undefined;+ const pageLabels = mode === "page" ? article?.labels : undefined;+ const published = pageLabels?.publishedDate;+ const modified = pageLabels?.modifiedDate;const button = SAVE_BUTTONS[mode ?? "page"];return (@@ -452,7 +455,18 @@ function PagePreview({ tab, disabled, shortcuts, draft, onDraftChange }: {><Icon icon={Calendar} /></span>- <span className="page-date">Published {published}</span>+ <span className="page-date page-published-date">Published {published}</span>+ </div>+ )}+ {modified && (+ <div className="page-field">+ <span+ className="page-field-icon"+ title="The date the page was last modified. It is saved in the #modifiedDate label of the note."+ >+ <Icon icon={History} />+ </span>+ <span className="page-date page-modified-date">Updated {modified}</span></div>)}</div>diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsxindex 249b63e6cd..8295a17d05 100644--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx@@ -25,7 +25,7 @@ const PAGE = {images: [ { imageId: "i1", src: "https://example.com/a.png" } ],pageUrl: "https://example.com/post?id=1",clipType: "page",- labels: { publishedDate: "2024-05-01" }+ labels: { publishedDate: "2024-05-01", modifiedDate: "2024-06-12" }};/** What `readable-page.js` returns in the tab, as `browser.scripting.executeScript()` answers. */const executeScript = vi.fn(async (): Promise<unknown> => [ { result: PAGE } ]);@@ -221,6 +221,11 @@ describe("popup", () => {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.");+ expect(modifiedDate()).toBe("Updated 2024-06-12");+ const modifiedIcon = container.querySelector<HTMLElement>(".page-fields > .page-field:nth-child(3) > .page-field-icon");+ expect(modifiedIcon?.querySelector("svg.icon path")).not.toBeNull();+ expect(modifiedIcon?.title).toBe(+ "The date the page was last modified. It is saved in the #modifiedDate 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));@@ -240,12 +245,13 @@ describe("popup", () => {expect(sendMessage).toHaveBeenLastCalledWith({ name: "save-whole-page", page: PAGE });});- it("leaves out the date of a page that has none", async () => {+ it("leaves out the dates of a page that states none", async () => {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();+ expect(modifiedDate()).toBeUndefined();});it("says so while the page is read", async () => {@@ -303,6 +309,7 @@ describe("popup", () => {expect(shortcutOf("Save selection").keys).toEqual([ "Ctrl", "Shift", "S" ]);expect(container.querySelector(".page-meta")?.textContent).toBe("example.com");expect(publishedDate()).toBeUndefined();+ expect(modifiedDate()).toBeUndefined();await click("Page");expect(modes()).toEqual([ [ "Selection", "false" ], [ "Page", "true" ], [ "Bookmark", "false" ] ]);@@ -365,6 +372,7 @@ describe("popup", () => {expect(container.querySelector<HTMLInputElement>(".page-title")?.value).toBe("An article");expect(container.querySelector(".page-meta")?.textContent).toBe("example.com");expect(publishedDate()).toBeUndefined();+ expect(modifiedDate()).toBeUndefined();expect(shortcutOf("Save bookmark")).toEqual({ text: "Ctrl+Enter", keys: [ "Ctrl", "Enter" ] });await type(".page-body .note-text", "Worth a read");@@ -409,7 +417,7 @@ describe("popup", () => {await click("Save page to Trilium");expect(sendMessage).toHaveBeenLastCalledWith({name: "save-whole-page",- page: { ...PAGE, labels: { publishedDate: "2024-05-01", pageDescription: "Edited description" } }+ page: { ...PAGE, labels: { ...PAGE.labels, pageDescription: "Edited description" } }});await click("Bookmark");@@ -432,7 +440,7 @@ describe("popup", () => {await click("Save page to Trilium");expect(sendMessage).toHaveBeenLastCalledWith({name: "save-whole-page",- page: { ...PAGE, labels: { publishedDate: "2024-05-01" } }+ page: PAGE});});@@ -446,7 +454,7 @@ describe("popup", () => {await click("Save page to Trilium");expect(sendMessage).toHaveBeenLastCalledWith({name: "save-whole-page",- page: { ...PAGE, labels: { publishedDate: "2024-05-01", pageDescription: "Written by hand" } }+ page: { ...PAGE, labels: { ...PAGE.labels, pageDescription: "Written by hand" } }});metadata = new Error("Could not establish connection.");@@ -778,5 +786,9 @@ function status() {}function publishedDate() {- return container.querySelector(".page-fields .page-date")?.textContent;+ return container.querySelector(".page-fields .page-published-date")?.textContent;+}++function modifiedDate() {+ return container.querySelector(".page-fields .page-modified-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.mdindex 2604c64d13..2221e95ff5 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. 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.+ * _Page_, when the page has an article: _Save page to Trilium_ saves the article's text and images. When the page states when it was published, that date 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. When it states when it was last modified, that date shows below, marked by the <span class="tn-icon bx bx-history"></span> icon, and is saved in the `#modifiedDate` label.* _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.