Skip to content

Build your personal knowledge base with Trilium Notes

feat(edit-docs): generate link to online resource

Elian Doran4c5b08108625
diff --git a/apps/edit-docs/src/edit-docs.ts b/apps/edit-docs/src/edit-docs.ts
index d680610cea..0096f6715d 100644
--- a/apps/edit-docs/src/edit-docs.ts
+++ b/apps/edit-docs/src/edit-docs.ts
@@ -246,7 +246,7 @@ async function cleanUpMeta(outputPath: string, minify: boolean) {
}
if (minify) {
- const subtree = new NodejsInAppHelpProvider().parseNoteMetaFile(meta);
+ const subtree = new NodejsInAppHelpProvider().parseNoteMetaFile(meta, BASE_URL);
await fs.writeFile(metaPath, JSON.stringify(subtree));
} else {
await fs.writeFile(metaPath, JSON.stringify(meta, null, 4));
diff --git a/apps/server/src/in_app_help_provider.ts b/apps/server/src/in_app_help_provider.ts
index ceb33b3039..6214432818 100644
--- a/apps/server/src/in_app_help_provider.ts
+++ b/apps/server/src/in_app_help_provider.ts
@@ -23,18 +23,18 @@ export default class NodejsInAppHelpProvider implements InAppHelpProvider {
}
}
- parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] {
+ parseNoteMetaFile(noteMetaFile: NoteMetaFile, baseUrl?: string): HiddenSubtreeItem[] {
if (!noteMetaFile.files) {
console.warn("No meta files found to parse.");
return [];
}
const metaRoot = noteMetaFile.files[0];
- const parsedMetaRoot = this.parseNoteMeta(metaRoot, "/" + (metaRoot.dirFileName ?? ""));
+ const parsedMetaRoot = this.parseNoteMeta(metaRoot, "/" + (metaRoot.dirFileName ?? ""), baseUrl);
return parsedMetaRoot?.children ?? [];
}
- parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string): HiddenSubtreeItem | null {
+ parseNoteMeta(noteMeta: NoteMeta, docNameRoot: string, parentUrl?: string): HiddenSubtreeItem | null {
let iconClass: string = "bx bx-file";
const item: HiddenSubtreeItem = {
id: `_help_${noteMeta.noteId}`,
@@ -49,6 +49,10 @@ export default class NodejsInAppHelpProvider implements InAppHelpProvider {
item.type = "book";
}
+ // Build the docUrl for this note
+ const shareAlias = this.getShareAlias(noteMeta);
+ const currentUrl = parentUrl && shareAlias ? `${parentUrl}/${shareAlias}` : parentUrl;
+
// Handle attributes
for (const attribute of noteMeta.attributes ?? []) {
if (attribute.name === "iconClass") {
@@ -77,6 +81,14 @@ export default class NodejsInAppHelpProvider implements InAppHelpProvider {
name: "docName",
value: docPath
});
+
+ if (currentUrl) {
+ item.attributes?.push({
+ type: "label",
+ name: "docUrl",
+ value: currentUrl
+ });
+ }
}
// Handle web views
@@ -90,7 +102,7 @@ export default class NodejsInAppHelpProvider implements InAppHelpProvider {
const children: HiddenSubtreeItem[] = [];
for (const childMeta of noteMeta.children) {
let newDocNameRoot = noteMeta.dirFileName ? `${docNameRoot}/${noteMeta.dirFileName}` : docNameRoot;
- const item = this.parseNoteMeta(childMeta, newDocNameRoot);
+ const item = this.parseNoteMeta(childMeta, newDocNameRoot, currentUrl);
if (item) {
children.push(item);
}
@@ -109,6 +121,10 @@ export default class NodejsInAppHelpProvider implements InAppHelpProvider {
return item;
}
+ private getShareAlias(noteMeta: NoteMeta): string | undefined {
+ return noteMeta.attributes?.find((a) => a.type === "label" && a.name === "shareAlias")?.value;
+ }
+
/**
* Iterates recursively through the help subtree that the user has and compares it against the definition
* to remove any notes that are no longer present in the latest version of the help.
diff --git a/apps/server/src/services/in_app_help.spec.ts b/apps/server/src/services/in_app_help.spec.ts
index 7c41d4b47a..b063d3aaa6 100644
--- a/apps/server/src/services/in_app_help.spec.ts
+++ b/apps/server/src/services/in_app_help.spec.ts
@@ -37,6 +37,127 @@ describe("In-app help", () => {
expect(icon?.value).toBe("bx bx-star");
});
+ it("generates docUrl from shareAlias when baseUrl is provided", () => {
+ const meta: NoteMeta = {
+ isClone: false,
+ noteId: "rootNote123",
+ notePath: [ "rootNote123" ],
+ title: "User Guide",
+ notePosition: 1,
+ prefix: null,
+ isExpanded: false,
+ type: "text",
+ mime: "text/html",
+ attributes: [
+ {
+ type: "label",
+ name: "shareAlias",
+ value: "user-guide",
+ isInheritable: false,
+ position: 10
+ }
+ ],
+ format: "html",
+ dataFileName: "User Guide.html",
+ dirFileName: "User Guide",
+ attachments: [],
+ children: [
+ {
+ isClone: false,
+ noteId: "childNote456",
+ notePath: [ "rootNote123", "childNote456" ],
+ title: "Feature Highlights",
+ notePosition: 10,
+ prefix: null,
+ isExpanded: false,
+ type: "text",
+ mime: "text/html",
+ attributes: [
+ {
+ type: "label",
+ name: "shareAlias",
+ value: "feature-highlights",
+ isInheritable: false,
+ position: 10
+ }
+ ],
+ format: "html",
+ dataFileName: "Feature Highlights.html",
+ attachments: [],
+ children: []
+ }
+ ]
+ };
+
+ const metaFile = { formatVersion: 2, appVersion: "0.103.0", files: [meta] };
+ const items = provider.parseNoteMetaFile(metaFile, "https://docs.triliumnotes.org");
+
+ // The root's children are returned, so items[0] is "Feature Highlights"
+ const child = items[0];
+ const docUrl = child?.attributes?.find((a) => a.name === "docUrl");
+ expect(docUrl?.value).toBe("https://docs.triliumnotes.org/user-guide/feature-highlights");
+ });
+
+ it("omits docUrl when no baseUrl is provided", () => {
+ const meta: NoteMeta = {
+ isClone: false,
+ noteId: "rootNote123",
+ notePath: [ "rootNote123" ],
+ title: "User Guide",
+ notePosition: 1,
+ prefix: null,
+ isExpanded: false,
+ type: "text",
+ mime: "text/html",
+ attributes: [
+ {
+ type: "label",
+ name: "shareAlias",
+ value: "user-guide",
+ isInheritable: false,
+ position: 10
+ }
+ ],
+ format: "html",
+ dataFileName: "User Guide.html",
+ dirFileName: "User Guide",
+ attachments: [],
+ children: [
+ {
+ isClone: false,
+ noteId: "childNote456",
+ notePath: [ "rootNote123", "childNote456" ],
+ title: "Feature Highlights",
+ notePosition: 10,
+ prefix: null,
+ isExpanded: false,
+ type: "text",
+ mime: "text/html",
+ attributes: [
+ {
+ type: "label",
+ name: "shareAlias",
+ value: "feature-highlights",
+ isInheritable: false,
+ position: 10
+ }
+ ],
+ format: "html",
+ dataFileName: "Feature Highlights.html",
+ attachments: [],
+ children: []
+ }
+ ]
+ };
+
+ const metaFile = { formatVersion: 2, appVersion: "0.103.0", files: [meta] };
+ const items = provider.parseNoteMetaFile(metaFile);
+
+ const child = items[0];
+ const docUrl = child?.attributes?.find((a) => a.name === "docUrl");
+ expect(docUrl).toBeUndefined();
+ });
+
it("hides note that is hidden from share tree", () => {
const meta: NoteMeta = {
isClone: false,
diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.ts
index 64a2ad48d7..7448c590ec 100644
--- a/packages/commons/src/lib/builtin_attributes.ts
+++ b/packages/commons/src/lib/builtin_attributes.ts
@@ -82,6 +82,7 @@ export default [
{ type: "label", name: "hideHighlightWidget" },
{ type: "label", name: "iconPack", isDangerous: true },
{ type: "label", name: "docName", isDangerous: true },
+ { type: "label", name: "docUrl", isDangerous: true },
{ type: "label", name: "tabWidth" },
{ type: "label", name: "indentWithTabs" },