Skip to content

Build your personal knowledge base with Trilium Notes

fix(share): keep notes hidden from the tree out of subpage lists

Elian Doran52e5a292c427
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
index 7728064462..000fccd41f 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
@@ -356,8 +356,8 @@ class="admonition note">
<tr>
<td><code>#shareHiddenFromTree</code>
</td>
- <td>this note is hidden from left navigation tree, but still accessible with
- its URL</td>
+ <td>this note is hidden from the left navigation tree and from its parent's
+ list of subpages, but still accessible with its URL</td>
</tr>
<tr>
<td><code>#shareExternalLink</code>
diff --git a/docs/User Guide/User Guide/Advanced Usage/Sharing.md b/docs/User Guide/User Guide/Advanced Usage/Sharing.md
index 6156a203b0..b24b9e8df1 100644
--- a/docs/User Guide/User Guide/Advanced Usage/Sharing.md
+++ b/docs/User Guide/User Guide/Advanced Usage/Sharing.md
@@ -244,7 +244,7 @@ The URL must be absolute and include the scheme (e.g. `https://`).
<tbody>
<tr>
<td><code>#shareHiddenFromTree</code></td>
- <td>this note is hidden from left navigation tree, but still accessible with its URL</td>
+ <td>this note is hidden from the left navigation tree and from its parent's list of subpages, but still accessible with its URL</td>
</tr>
<tr>
<td><code>#shareExternalLink</code></td>
diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejs
index 4469834aaf..d8cf6db8cd 100644
--- a/packages/share-theme/src/templates/page.ejs
+++ b/packages/share-theme/src/templates/page.ejs
@@ -182,8 +182,7 @@ content = content.replaceAll(headingRe, (...match) => {
<ul>
<%
- const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes";
- for (const childNote of note[action]()) {
+ for (const childNote of note.getVisibleChildNotes()) {
const externalHref = childNote
.getLabelValue("shareExternalLink")?.trim()
|| childNote.getLabelValue("shareExternal")?.trim();
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index e5feab41f2..2e590055e9 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -1017,6 +1017,21 @@ describe("content_renderer", () => {
.toEqual([ "class", "href" ]);
});
+ it("leaves notes hidden from the tree out of a book's subpage list", () => {
+ buildShareNote({
+ id: "bookParent",
+ type: "book",
+ content: "",
+ children: [
+ { id: "bookVisible", title: "Visible" },
+ { "id": "bookHidden", "title": "Hidden", "#shareHiddenFromTree": "" }
+ ]
+ });
+
+ const titles = renderPageAnchors("bookParent").map((a) => a.textContent);
+ expect(titles).toEqual([ "Visible" ]);
+ });
+
function renderPageAnchors(noteId: string) {
const note = shaca.getNote(noteId);
const { header, content, isEmpty } = getContent(note);
diff --git a/packages/trilium-core/src/share/handlers.spec.ts b/packages/trilium-core/src/share/handlers.spec.ts
index 5f6a7f2342..4714b4688e 100644
--- a/packages/trilium-core/src/share/handlers.spec.ts
+++ b/packages/trilium-core/src/share/handlers.spec.ts
@@ -88,6 +88,21 @@ describe("share handlers", () => {
expect(request("/share/:shareId", { params: { shareId: "openNote" }, query: { raw: "" } }).body).toBe("<p>public body</p>");
});
+ it("lists only the children visible in the tree in a note's JSON", () => {
+ buildShareTree([ {
+ id: "jsonParent",
+ content: "<p>Parent</p>",
+ children: [
+ { id: "jsonVisible", content: "<p>Visible</p>" },
+ { "id": "jsonHidden", "content": "<p>Hidden</p>", "#shareHiddenFromTree": "" }
+ ]
+ } ]);
+
+ const reply = request("/share/api/notes/:noteId", { params: { noteId: "jsonParent" } });
+ expect(reply.status).toBe(200);
+ expect(JSON.parse(String(reply.body))).toMatchObject({ childNoteIds: [ "jsonVisible" ] });
+ });
+
it("asks for credentials until matching HTTP Basic ones arrive", () => {
buildShareTree([ { id: "lockedNote", content: "<p>classified</p>", "#shareCredentials": "root:hunter2" } ]);
diff --git a/packages/trilium-core/src/share/shaca/entities/snote.ts b/packages/trilium-core/src/share/shaca/entities/snote.ts
index 6667081509..979120f543 100644
--- a/packages/trilium-core/src/share/shaca/entities/snote.ts
+++ b/packages/trilium-core/src/share/shaca/entities/snote.ts
@@ -523,7 +523,7 @@ class SNote extends AbstractShacaEntity {
.map((attr) => attr.getPojo()),
attachments: this.getAttachments().map((attachment) => attachment.getPojo()),
parentNoteIds: this.parents.map((parentNote) => parentNote.noteId),
- childNoteIds: this.children.map((child) => child.noteId)
+ childNoteIds: this.getVisibleChildNotes().map((child) => child.noteId)
};
}