Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/main' into web-clipper-prevent-note-cloning

Elian Doran7f46a4765f92
diff --cc apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Web Clipper.html
index ade0f6dad1,673ce63864..1224e2e4e3
--- 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
@@@ -30,12 -84,11 +84,13 @@@
<h2>Location of clippings</h2>
<p>Trilium will save these clippings as a new child note under a "clipper
inbox" note.</p>
- <p>By default, that's the <a href="#root/_help_l0tKav7yLHGF">day note</a> but you
- can override that by setting the <a href="#root/_help_zEY4DaJG4YT5">label</a>
- <code
- spellcheck="false">clipperInbox</code>, on any other note.</p>
- <p>If there's multiple clippings from the same page (and on the same day),
- then they will be added to the same note.</p>
+ <p>By default, that's the&nbsp;<a class="reference-link" href="#root/_help_l0tKav7yLHGF">Day Notes</a>&nbsp;but
+ you can override that by setting the <a href="#root/_help_zEY4DaJG4YT5">label</a> <code>clipperInbox</code>,
+ on any other note.</p>
-<p>If there's multiple clippings from the same page (and on the same day),
- then they will be added to the same note.</p>
++<p>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.</p>
<h2>Keyboard shortcuts</h2>
<p>Keyboard shortcuts are available for most functions:</p>
<ul>
diff --cc apps/server/src/routes/api/clipper.spec.ts
index d95570117b,f2e19834d5..7713bb82f8
--- a/apps/server/src/routes/api/clipper.spec.ts
+++ b/apps/server/src/routes/api/clipper.spec.ts
@@@ -1,8 -1,8 +1,8 @@@
- import { becca_easy_mocking, BNote } from "@triliumnext/core";
-import { BBranch, becca, becca_easy_mocking, BNote, cls } from "@triliumnext/core";
++import { BBranch, becca, becca_easy_mocking, BNote, branches, cls } from "@triliumnext/core";
+ import type { Request } from "express";
import { beforeAll, describe, expect, it, vi } from "vitest";
- import { cls } from "@triliumnext/core";
- import { processContent } from "./clipper";
+ import clipperRoute, { processContent } from "./clipper";
const { buildNote } = becca_easy_mocking;
@@@ -54,3 -58,81 +58,102 @@@ describe("processContent", () =>
}
});
});
+
+ // These exercise the route handlers against the real in-memory DB.
+ describe("clipper route handlers", () => {
+ it("returns the handshake metadata", () => {
+ const result = clipperRoute.handshake();
+ expect(result.appName).toBe("trilium");
+ expect(result.protocolVersion).toBeTruthy();
+ });
+
+ it("reports open-in-browser when not running under Electron", () => {
+ const req = { params: { noteId: "root" } } as unknown as Request<{ noteId: string }>;
+ expect(clipperRoute.openNote(req)).toEqual({ result: "open-in-browser" });
+ });
+
+ it("creates a clipping note, then appends to it when clipped from the same URL", async () => {
+ const pageUrl = "https://example.com/article";
+ const first = await cls.init(() => clipperRoute.addClipping({
+ body: { title: "Article", content: "<p>first</p>", images: [], pageUrl }
+ } as unknown as Request));
+ expect(first.noteId).toBeTruthy();
+
+ const second = await cls.init(() => clipperRoute.addClipping({
+ body: { title: "Article", content: "<p>second</p>", images: [], pageUrl }
+ } as unknown as Request));
+ // Same pageUrl → appends to the existing clipping note.
+ expect(second.noteId).toBe(first.noteId);
+
+ const found = await cls.init(() => clipperRoute.findNotesByUrl({ params: { noteUrl: pageUrl } } as unknown as Request<{ noteUrl: string }>));
+ expect(found.noteId).toBe(first.noteId);
+ });
+
++ it("appends to a clipping note moved out of the inbox without cloning it back", async () => {
++ const pageUrl = "https://example.com/moved";
++ const first = await cls.init(() => clipperRoute.addClipping({
++ body: { title: "Moved", content: "<p>first</p>", images: [], pageUrl }
++ } as unknown as Request));
++ const clipping = becca.getNoteOrThrow(first.noteId);
++ const [ inboxBranch ] = clipping.getParentBranches();
++ expect(inboxBranch).toBeDefined();
++
++ const folder = buildNote({ title: "Reading list" });
++ new BBranch({ noteId: folder.noteId, parentNoteId: "root", branchId: `root_${folder.noteId}` });
++ cls.init(() => branches.moveBranchToNote(inboxBranch, folder.noteId));
++ expect(clipping.getParentNotes().map((p) => p.noteId)).toEqual([ folder.noteId ]);
++
++ const second = await cls.init(() => clipperRoute.addClipping({
++ body: { title: "Moved", content: "<p>second</p>", images: [], pageUrl }
++ } as unknown as Request));
++ expect(second.noteId).toBe(first.noteId);
++ expect(clipping.getParentNotes().map((p) => p.noteId)).toEqual([ folder.noteId ]);
++ });
++
+ it("creates a standalone note with labels", async () => {
+ const result = await cls.init(() => clipperRoute.createNote({
+ body: {
+ title: "Clipped",
+ content: "<p>body</p>",
+ images: [],
+ clipType: "note",
+ pageUrl: "https://example.com/page",
+ labels: { source: "web" }
+ }
+ } as unknown as Request));
+ expect(result.noteId).toBeTruthy();
+ });
+
+ it("clips to the top level when there is no clipper inbox and no journal", async () => {
+ const result = await cls.init(() => clipperRoute.createNote({
+ body: { title: "No journal", content: "<p>x</p>", images: [], clipType: "note", pageUrl: "https://example.com/nj" }
+ } as unknown as Request));
+
+ // Without a #calendarRoot the clipping must not have a calendar built around it.
+ const clipped = becca.getNoteOrThrow(result.noteId);
+ expect(clipped.getParentNotes().map((p) => p.noteId)).toEqual([ "root" ]);
+ });
+
+ it("clips into the day note once a journal exists", async () => {
+ const journal = buildNote({ title: "Journal", "#calendarRoot": "" });
+ // The day note is created beneath it, so it needs a path back to the root.
+ new BBranch({ noteId: journal.noteId, parentNoteId: "root", branchId: `root_${journal.noteId}` });
+
+ const result = await cls.init(() => clipperRoute.createNote({
+ body: { title: "With journal", content: "<p>x</p>", images: [], clipType: "note", pageUrl: "https://example.com/wj" }
+ } as unknown as Request));
+
+ const clipped = becca.getNoteOrThrow(result.noteId);
+ expect(clipped.getParentNotes().map((p) => p.noteId)).not.toEqual([ "root" ]);
+ });
+
+ it("returns a null noteId when no clipping matches the URL", async () => {
+ const found = await cls.init(() => clipperRoute.findNotesByUrl({ params: { noteUrl: "https://nope.example/none" } } as unknown as Request<{ noteUrl: string }>));
+ expect(found.noteId).toBeNull();
+ });
+
+ it("returns a null noteId for an empty URL", async () => {
+ const found = await cls.init(() => clipperRoute.findNotesByUrl({ params: { noteUrl: "" } } as unknown as Request<{ noteUrl: string }>));
+ expect(found.noteId).toBeNull();
+ });
+ });
diff --cc apps/server/src/routes/api/clipper.ts
index 69a54283ef,5dcdab5849..5603ae431f
--- a/apps/server/src/routes/api/clipper.ts
+++ b/apps/server/src/routes/api/clipper.ts
@@@ -1,4 -1,4 +1,4 @@@
- import { app_info as appInfo, attribute_formatter as attributeFormatter, attributes as attributeService, type BNote, cloning as cloneService, date_notes as dateNoteService, date_utils as dateUtils, getLog, note_service as noteService, sanitize, search as searchService, ValidationError, ws } from "@triliumnext/core";
-import { app_info as appInfo, attribute_formatter as attributeFormatter, attributes as attributeService, becca, type BNote, cloning as cloneService, date_notes as dateNoteService, date_utils as dateUtils, note_service as noteService, sanitize, ValidationError, ws } from "@triliumnext/core";
++import { app_info as appInfo, attribute_formatter as attributeFormatter, attributes as attributeService, becca, type BNote, date_notes as dateNoteService, date_utils as dateUtils, getLog, note_service as noteService, sanitize, search as searchService, ValidationError, ws } from "@triliumnext/core";
import type { Request } from "express";
import { parse } from "node-html-parser";
import path from "path";
diff --cc docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
index 81f0883fc2,341e23ec13..9cb863dea0
--- a/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Web Clipper.md
@@@ -29,9 -46,9 +46,9 @@@ Clicking the extension's button in the
Trilium will save these clippings as a new child note under a "clipper inbox" note.
- By default, that's the [day note](../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) but you can override that by setting the [label](../Advanced%20Usage/Attributes.md) `clipperInbox`, on any other note.
+ By default, that's the <a class="reference-link" href="../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a> but you can override that by setting the [label](../Advanced%20Usage/Attributes.md) `clipperInbox`, on any other note.
--If there's multiple clippings from the same page (and on the same day), then they will be added to the same note.
++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.
## Keyboard shortcuts