Skip to content

Build your personal knowledge base with Trilium Notes

fix(clipper): save each set of tabs to a new note

Elian Doran55b68f9c8cc5
diff --git a/apps/server/src/routes/api/clipper.spec.ts b/apps/server/src/routes/api/clipper.spec.ts
index d0bc5ef6f4..acb79b6ef7 100644
--- a/apps/server/src/routes/api/clipper.spec.ts
+++ b/apps/server/src/routes/api/clipper.spec.ts
@@ -213,6 +213,22 @@ describe("clipper route handlers", () => {
expect(clipped.getParentNotes().map((p) => p.noteId)).not.toEqual([ "root" ]);
});
+ it("creates a new note for each clipping that names no page", async () => {
+ const save = () => cls.init(() => clipperRoute.createNote({
+ body: { title: "Tabs", content: "<p>tabs</p>", clipType: "tabs" }
+ } as unknown as Request));
+
+ const first = await save();
+ const second = await save();
+
+ expect(second.noteId).not.toBe(first.noteId);
+ for (const { noteId } of [ first, second ]) {
+ const note = becca.getNoteOrThrow(noteId);
+ expect(note.hasLabel("pageUrl")).toBe(false);
+ expect(note.getContent()).toBe("<p>tabs</p>");
+ }
+ });
+
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();
diff --git a/apps/server/src/routes/api/clipper.ts b/apps/server/src/routes/api/clipper.ts
index 6a23c498be..b7012fab1c 100644
--- a/apps/server/src/routes/api/clipper.ts
+++ b/apps/server/src/routes/api/clipper.ts
@@ -91,7 +91,7 @@ async function createNote(req: Request) {
const { content, images, labels } = req.body;
const clipType = sanitize.sanitizeHtml(req.body.clipType);
- const pageUrl = sanitize.sanitizeUrl(req.body.pageUrl);
+ const pageUrl = req.body.pageUrl ? sanitize.sanitizeUrl(req.body.pageUrl) : "";
const trimmedTitle = (typeof req.body.title === "string") ? req.body.title.trim() : "";
const title = trimmedTitle || `Clipped note from ${pageUrl}`;