Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(share): link a note by its ID when another note took its alias
Elian Doranb5d1cfd199de
diff --git a/packages/trilium-core/src/share/shaca/entities/snote.spec.ts b/packages/trilium-core/src/share/shaca/entities/snote.spec.tsindex 85c3d78873..2a14e439ca 100644--- a/packages/trilium-core/src/share/shaca/entities/snote.spec.ts+++ b/packages/trilium-core/src/share/shaca/entities/snote.spec.ts@@ -194,6 +194,10 @@ describe("SNote", () => {expect([ parent, aliased, root ].map((note) => note.shareId)).toEqual([ "parent", "my-alias", "" ]);++ // `/share/my-alias` opens the note that took the alias last, so the other one links by ID.+ const sameAlias = buildShareNote({ id: "sameAlias", "#shareAlias": " my-alias " });+ expect([ aliased, sameAlias ].map((note) => note.shareId)).toEqual([ "aliased", "my-alias" ]);expect(parent.escapedTitle).toBe("Tom & Jerry");expect(parent.encodedTitle).toBe("Tom%20%26%20Jerry");expect(parent.getAttachmentByTitle("Diagram")?.getPojo().attachmentId).toBe("att");diff --git a/packages/trilium-core/src/share/shaca/entities/snote.ts b/packages/trilium-core/src/share/shaca/entities/snote.tsindex 08b256f206..36ece31afd 100644--- a/packages/trilium-core/src/share/shaca/entities/snote.ts+++ b/packages/trilium-core/src/share/shaca/entities/snote.ts@@ -482,9 +482,10 @@ class SNote extends AbstractShacaEntity {return "";}- const sharedAlias = this.getOwnedLabelValue("shareAlias");-- return sharedAlias || this.noteId;+ // Of notes sharing an alias, `/share/<alias>` opens one; the others link by their ID.+ const sharedAlias = this.getOwnedLabelValue("shareAlias")?.trim();+ const ownsAlias = sharedAlias && this.shaca.aliasToNote[sharedAlias] === this;+ return ownsAlias ? sharedAlias : this.noteId;}get escapedTitle() {