Skip to content

Build your personal knowledge base with Trilium Notes

fix(clipper): stop clipping from rebuilding a deleted journal

Elian Doranaffdf292580b
diff --git a/apps/server/src/routes/api/clipper.spec.ts b/apps/server/src/routes/api/clipper.spec.ts
index e86d55c844..7c637daf4c 100644
--- a/apps/server/src/routes/api/clipper.spec.ts
+++ b/apps/server/src/routes/api/clipper.spec.ts
@@ -1,4 +1,4 @@
-import { becca_easy_mocking, BNote, cls } from "@triliumnext/core";
+import { BBranch, becca, becca_easy_mocking, BNote, cls } from "@triliumnext/core";
import type { Request } from "express";
import { beforeAll, describe, expect, it, vi } from "vitest";
@@ -102,6 +102,29 @@ describe("clipper route handlers", () => {
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();
diff --git a/apps/server/src/routes/api/clipper.ts b/apps/server/src/routes/api/clipper.ts
index 0b7f94fbae..5dcdab5849 100644
--- a/apps/server/src/routes/api/clipper.ts
+++ b/apps/server/src/routes/api/clipper.ts
@@ -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, 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, cloning as cloneService, date_notes as dateNoteService, date_utils as dateUtils, note_service as noteService, sanitize, ValidationError, ws } from "@triliumnext/core";
import type { Request } from "express";
import { parse } from "node-html-parser";
import path from "path";
@@ -77,13 +77,18 @@ function findClippingNote(clipperInboxNote: BNote, pageUrl: string, clipType: st
}
async function getClipperInboxNote() {
- let clipperInbox = attributeService.getNoteWithLabel("clipperInbox");
+ const clipperInbox = attributeService.getNoteWithLabel("clipperInbox");
+ if (clipperInbox) {
+ return clipperInbox;
+ }
- if (!clipperInbox) {
- clipperInbox = await dateNoteService.getDayNote(dateUtils.localNowDate());
+ // Clipping a page is not a request for a journal, so a database without one keeps the
+ // clipping at the top level rather than having a calendar built around it (#11034).
+ if (!dateNoteService.hasCalendarRoot()) {
+ return becca.getNoteOrThrow("root");
}
- return clipperInbox;
+ return await dateNoteService.getDayNote(dateUtils.localNowDate());
}
async function createNote(req: Request) {