Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): give virtual text notes the text/html mime

Elian Doran022746ebc767
diff --git a/apps/server/spec/in_app_help.spec.ts b/apps/server/spec/in_app_help.spec.ts
index 40a6a24bc0..c3d6f15cb9 100644
--- a/apps/server/spec/in_app_help.spec.ts
+++ b/apps/server/spec/in_app_help.spec.ts
@@ -57,12 +57,14 @@ describe("in-app help (shipped artifacts)", () => {
// build copies the same tree into the package.
const assetRoot = path.resolve(__dirname, "../../../docs/User Guide");
const missing: string[] = [];
+ let assetCount = 0;
for (const page of contentPages(meta)) {
const html = String(becca.getNoteOrThrow(page.id).getContent());
expect(html, `page ${page.id} still carries an unsubstituted asset placeholder`).not.toContain(HELP_ASSET_TOKEN);
for (const match of html.matchAll(/(?:src|href)="([^"]*\/help\/[^"]*)"/g)) {
+ assetCount++;
const relative = decodeURIComponent(match[1].split("/help/")[1]);
if (!fs.existsSync(path.join(assetRoot, relative))) {
missing.push(`${page.title} -> ${relative}`);
@@ -70,6 +72,7 @@ describe("in-app help (shipped artifacts)", () => {
}
}
+ expect(assetCount).toBeGreaterThan(0);
expect(missing).toEqual([]);
});
diff --git a/packages/trilium-core/src/becca/becca_loader.ts b/packages/trilium-core/src/becca/becca_loader.ts
index d1f860b83e..7f6ee2e2fd 100644
--- a/packages/trilium-core/src/becca/becca_loader.ts
+++ b/packages/trilium-core/src/becca/becca_loader.ts
@@ -127,7 +127,9 @@ function injectVirtualSubtrees() {
// notes still need the target-relation backfill below.
injectedAny = true;
- subtree.forEach((item, index) => injectVirtualItem(provider, provider.parentNoteId, item, basePosition + (index + 1) * 10));
+ for (const [index, item] of subtree.entries()) {
+ injectVirtualItem(provider, provider.parentNoteId, item, basePosition + (index + 1) * 10);
+ }
} catch (e) {
// A broken provider must never take down the becca load.
log.error(`Virtual note provider '${provider.namespace}' failed, skipping: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}`);
@@ -172,7 +174,7 @@ function injectVirtualItem(provider: VirtualNoteProvider, parentNoteId: string,
noteId: item.id,
title: item.title,
type: item.type,
- mime: item.mime ?? "",
+ mime: item.mime ?? (item.type === "text" ? "text/html" : ""),
isProtected: false,
dateCreated: dateUtils.localNowDateTime(),
dateModified: dateUtils.localNowDateTime(),
@@ -212,7 +214,7 @@ function injectVirtualItem(provider: VirtualNoteProvider, parentNoteId: string,
attributeDefs.push({ type: "label", name: "iconClass", value: `bx ${item.icon}` });
}
- attributeDefs.forEach((def, index) => {
+ for (const [index, def] of attributeDefs.entries()) {
// Deterministic ID, unique thanks to the note-ID prefix; the counter suffix
// disambiguates multiple same-named attributes on one note, probing until free so
// pathological names (e.g. "x" colliding with an explicit "x_1") cannot overwrite.
@@ -232,9 +234,11 @@ function injectVirtualItem(provider: VirtualNoteProvider, parentNoteId: string,
position: (index + 1) * 10
});
attribute.isVirtual = true;
- });
+ }
- (item.children ?? []).forEach((child, index) => injectVirtualItem(provider, item.id, child, (index + 1) * 10));
+ for (const [index, child] of (item.children ?? []).entries()) {
+ injectVirtualItem(provider, item.id, child, (index + 1) * 10);
+ }
}
/**
diff --git a/packages/trilium-core/src/becca/virtual_notes_injection.spec.ts b/packages/trilium-core/src/becca/virtual_notes_injection.spec.ts
index d45c606c85..910d645492 100644
--- a/packages/trilium-core/src/becca/virtual_notes_injection.spec.ts
+++ b/packages/trilium-core/src/becca/virtual_notes_injection.spec.ts
@@ -73,6 +73,10 @@ describe("virtual note injection", () => {
expect(root.isVirtual).toBe(true);
expect(root.title).toBe("Virtual root");
expect(root.type).toBe("book");
+ expect(root.mime).toBe("");
+ // A text page without a mime of its own gets the one every text note carries, which
+ // the full-text search needs to read its markup as HTML.
+ expect(becca.getNoteOrThrow("_vtestPage").mime).toBe("text/html");
expect(root.getParentNotes().map((note) => note.noteId)).toEqual(["_hidden"]);
expect(root.getChildNotes().map((note) => note.noteId)).toEqual(["_vtestPage", "_vtestLinked", "_vtestLast"]);
diff --git a/packages/trilium-core/src/services/hidden_subtree.ts b/packages/trilium-core/src/services/hidden_subtree.ts
index 18e9438ed7..e97831b2bb 100644
--- a/packages/trilium-core/src/services/hidden_subtree.ts
+++ b/packages/trilium-core/src/services/hidden_subtree.ts
@@ -349,9 +349,6 @@ function buildHiddenSubtreeDefinition(): HiddenSubtreeItem {
{ id: "_optionsAdvanced", title: t("hidden-subtree.advanced-title"), type: "contentWidget" }
]
},
- // The in-app help (`_help`) is deliberately absent here: it is a virtual subtree
- // injected into becca by the provider registered in `services/in_app_help.ts`,
- // never persisted or synced.
buildHiddenSubtreeTemplates()
]
};