Skip to content

Build your personal knowledge base with Trilium Notes

feat(clipper): derive a clipping's icon from its clip type

Elian Doranee9e01f2eed7
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 0c13b60332..ba2d2f4d0d 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
@@ -116,6 +116,16 @@
note created by the first one, even on a later day or after that note was
moved out of the clipper inbox. The note stays where it is and is not cloned
back into the inbox.</p>
+<p>The icon of a clipped note shows what was saved:</p>
+<ul>
+ <li><span class="tn-icon bx bx-paperclip"></span> a selection, a screenshot
+ or a link from the context menu;</li>
+ <li><span class="tn-icon bx bx-globe"></span> a page (<em>Article</em> or <em>Whole page</em>);</li>
+ <li><span class="tn-icon bx bx-bookmark"></span> a bookmark;</li>
+ <li><span class="tn-icon bx bx-window-alt"></span> the tabs of a window.</li>
+</ul>
+<p>The icon is derived from the note's <code>#clipType</code> label, so setting
+ an <code>#iconClass</code> label on the note replaces it.</p>
<h2>Embedded videos</h2>
<p>A YouTube video embedded in a clipped page is saved as a <a class="reference-link"
href="#root/_help_UmgZAfcltxkS">Link Previews</a> embed, with the video's
diff --git a/apps/server/src/routes/api/clipper.ts b/apps/server/src/routes/api/clipper.ts
index 2cef1ceeb1..29470d45f9 100644
--- a/apps/server/src/routes/api/clipper.ts
+++ b/apps/server/src/routes/api/clipper.ts
@@ -41,7 +41,6 @@ async function addClipping(req: Request) {
clippingNote.setLabel("clipType", "clippings");
clippingNote.setLabel("pageUrl", pageUrl);
- clippingNote.setLabel("iconClass", "bx bx-globe");
}
setLabels(clippingNote, labels);
@@ -118,7 +117,6 @@ async function createNote(req: Request) {
if (pageUrl) {
note.setLabel("pageUrl", pageUrl);
- note.setLabel("iconClass", "bx bx-globe");
}
}
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 8369587f32..81307b6738 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
@@ -52,6 +52,15 @@ By default, that's the <a class="reference-link" href="../Advanced%20Usage/Adva
Further clippings of the same kind from the same page are added to the note created by the first one, even on a later day or after that note was moved out of the clipper inbox. The note stays where it is and is not cloned back into the inbox.
+The icon of a clipped note shows what was saved:
+
+* <span class="tn-icon bx bx-paperclip"></span> a selection, a screenshot or a link from the context menu;
+* <span class="tn-icon bx bx-globe"></span> a page (_Article_ or _Whole page_);
+* <span class="tn-icon bx bx-bookmark"></span> a bookmark;
+* <span class="tn-icon bx bx-window-alt"></span> the tabs of a window.
+
+The icon is derived from the note's `#clipType` label, so setting an `#iconClass` label on the note replaces it.
+
## Embedded videos
A YouTube video embedded in a clipped page is saved as a <a class="reference-link" href="../Note%20Types/Text/Link%20Previews.md">Link Previews</a> embed, with the video's title and thumbnail. As with a link preview added in the editor, the video plays only when clicked. Other embedded content (such as videos from other websites) is not saved.
diff --git a/packages/commons/src/lib/notes.spec.ts b/packages/commons/src/lib/notes.spec.ts
index 9963435d3d..973bdb6081 100644
--- a/packages/commons/src/lib/notes.spec.ts
+++ b/packages/commons/src/lib/notes.spec.ts
@@ -111,6 +111,21 @@ describe("getNoteIcon", () => {
}))).toBe("bx bx-trip");
});
+ it("draws a web clipping by its clip type, behind its own icon", () => {
+ const clipped = (clipType: string) => (name: string) => name === "clipType" ? clipType : null;
+
+ expect([ "clippings", "page", "note", "tabs" ].map((clipType) =>
+ getNoteIcon(buildArgs({ getLabelValue: clipped(clipType) }))))
+ .toEqual([ "bx bx-paperclip", "bx bx-globe", "bx bx-bookmark", "bx bx-window-alt" ]);
+ expect(getNoteIcon(buildArgs({ getLabelValue: clipped("page"), isFolder: () => true })))
+ .toBe("bx bx-globe");
+ expect(getNoteIcon(buildArgs({ getLabelValue: clipped("page"), iconClass: "bx bx-star" })))
+ .toBe("bx bx-star");
+ for (const clipType of [ "unknown", "constructor" ]) {
+ expect(getNoteIcon(buildArgs({ getLabelValue: clipped(clipType) }))).toBe("bx bx-note");
+ }
+ });
+
it("draws a shape note as the shape its label names, by the same rules as a pin", () => {
const drawn = (value: string) =>
(name: string) => name === GEO_SHAPE_ATTRIBUTE ? value : null;
diff --git a/packages/commons/src/lib/notes.ts b/packages/commons/src/lib/notes.ts
index 5a4f700477..fc3d8b0dbf 100644
--- a/packages/commons/src/lib/notes.ts
+++ b/packages/commons/src/lib/notes.ts
@@ -134,6 +134,14 @@ export const GEO_SHAPE_ICONS: Record<string, string> = {
circle: "bx bx-shape-circle"
};
+/** The icon of a note made by the web clipper, keyed by its `#clipType` label. */
+export const CLIP_TYPE_ICONS: ReadonlyMap<string, string> = new Map([
+ [ "clippings", "bx bx-paperclip" ],
+ [ "page", "bx bx-globe" ],
+ [ "note", "bx bx-bookmark" ],
+ [ "tabs", "bx bx-window-alt" ]
+]);
+
/**
* The icon a note is drawn under: its own `#iconClass` where it has one, and a default read off
* what the note is otherwise.
@@ -143,7 +151,8 @@ export const GEO_SHAPE_ICONS: Record<string, string> = {
* The geo map therefore writes no `#iconClass` onto a marker or a shape it creates, so an icon it
* hands down through
* `#child:iconClass` or a template still applies, and redrawing a shape as another kind changes the
- * icon with it. `iconClass` stays an argument rather than being read here because the share tree
+ * icon with it. A note the web clipper made is drawn by its `#clipType` ({@link CLIP_TYPE_ICONS}).
+ * `iconClass` stays an argument rather than being read here because the share tree
* narrows it to the prefixes an icon pack supplies.
*/
export function getNoteIcon({
@@ -177,6 +186,10 @@ export function getNoteIcon({
if (shape) {
return GEO_SHAPE_ICONS[shape.split(":", 1)[0]] ?? GEO_SHAPE_ICONS.line;
}
+ const clipIcon = CLIP_TYPE_ICONS.get(getLabelValue("clipType") ?? "");
+ if (clipIcon) {
+ return clipIcon;
+ }
if (isFolder()) {
return "bx bx-folder";
}