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
share tree should include branch prefixes, fixes #4096
zadamd6a4f1db1302
diff --git a/src/share/routes.js b/src/share/routes.jsindex c5836f177c..72e80c6400 100644--- a/src/share/routes.js+++ b/src/share/routes.js@@ -9,21 +9,28 @@ const contentRenderer = require("./content_renderer");const assetPath = require("../services/asset_path");const appPath = require("../services/app_path");+/**+ * @param {SNote} note+ * @return {{note: SNote, branch: SBranch}|{}}+ */function getSharedSubTreeRoot(note) {if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {// share root itself is not shared- return null;+ return {};}// every path leads to share root, but which one to choose?// for the sake of simplicity, URLs are not note paths- const parentNote = note.getParentNotes()[0];+ const parentBranch = note.getParentBranches()[0];- if (parentNote.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {- return note;+ if (parentBranch.parentNoteId === shareRoot.SHARE_ROOT_NOTE_ID) {+ return {+ note,+ branch: parentBranch+ };}- return getSharedSubTreeRoot(parentNote);+ return getSharedSubTreeRoot(parentBranch.getParentNote());}function addNoIndexHeader(note, res) {diff --git a/src/share/shaca/entities/sbranch.js b/src/share/shaca/entities/sbranch.jsindex ab3febfa94..a6f2ac13ad 100644--- a/src/share/shaca/entities/sbranch.js+++ b/src/share/shaca/entities/sbranch.js@@ -52,6 +52,11 @@ class SBranch extends AbstractShacaEntity {get parentNote() {return this.shaca.notes[this.parentNoteId];}++ /** @returns {SNote} */+ getParentNote() {+ return this.parentNote;+ }}module.exports = SBranch;diff --git a/src/share/shaca/entities/snote.js b/src/share/shaca/entities/snote.jsindex 05dba63bb9..00ef3292d6 100644--- a/src/share/shaca/entities/snote.js+++ b/src/share/shaca/entities/snote.js@@ -68,6 +68,13 @@ class SNote extends AbstractShacaEntity {return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));}+ /** @returns {SBranch[]} */+ getVisibleChildBranches() {+ return this.getChildBranches()+ .filter(branch => !branch.isHidden+ && !branch.getNote().isLabelTruthy('shareHiddenFromTree'));+ }+/** @returns {SNote[]} */getParentNotes() {return this.parents;@@ -80,10 +87,8 @@ class SNote extends AbstractShacaEntity {/** @returns {SNote[]} */getVisibleChildNotes() {- return this.getChildBranches()- .filter(branch => !branch.isHidden)- .map(branch => branch.getNote())- .filter(childNote => !childNote.isLabelTruthy('shareHiddenFromTree'));+ return this.getVisibleChildBranches()+ .map(branch => branch.getNote());}/** @returns {boolean} */diff --git a/src/views/share/page.ejs b/src/views/share/page.ejsindex 2bdb1050ed..52e891dbcf 100644--- a/src/views/share/page.ejs+++ b/src/views/share/page.ejs@@ -75,11 +75,11 @@<% } %></div>- <% if (subRoot.hasVisibleChildren()) { %>+ <% if (subRoot.note.hasVisibleChildren()) { %><button id="toggleMenuButton"></button><nav id="menu">- <%- include('tree_item', {note: subRoot, activeNote: note}) %>+ <%- include('tree_item', {note: subRoot.note, branch: subRoot.branch, activeNote: note}) %></nav><% } %></div>diff --git a/src/views/share/tree_item.ejs b/src/views/share/tree_item.ejsindex 9d310f0038..12eec3fbb9 100644--- a/src/views/share/tree_item.ejs+++ b/src/views/share/tree_item.ejs@@ -1,16 +1,18 @@<p>+ <% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %>+<% if (activeNote.noteId === note.noteId) { %>- <strong><%= note.title %></strong>+ <strong><%= titleWithPrefix %></strong><% } else { %>- <a class="type-<%= note.type %>" href="./<%= note.shareId %>"><%= note.title %></a>+ <a class="type-<%= note.type %>" href="./<%= note.shareId %>"><%= titleWithPrefix %></a><% } %></p><% if (note.hasChildren()) { %><ul>- <% note.getVisibleChildNotes().forEach(function (childNote) { %>+ <% note.getVisibleChildBranches().forEach(function (branch) { %><li>- <%- include('tree_item', {note: childNote}) %>+ <%- include('tree_item', {branch: branch, note: branch.getNote()}) %></li><% }) %></ul>