diff --git a/src/share/routes.js b/src/share/routes.js index c5836f177..72e80c640 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.js index ab3febfa9..a6f2ac13a 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.js index 05dba63bb..00ef3292d 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.ejs index 2bdb1050e..52e891dbc 100644 --- a/src/views/share/page.ejs +++ b/src/views/share/page.ejs @@ -75,11 +75,11 @@ <% } %> - <% if (subRoot.hasVisibleChildren()) { %> + <% if (subRoot.note.hasVisibleChildren()) { %> <% } %> diff --git a/src/views/share/tree_item.ejs b/src/views/share/tree_item.ejs index 9d310f003..12eec3fbb 100644 --- a/src/views/share/tree_item.ejs +++ b/src/views/share/tree_item.ejs @@ -1,16 +1,18 @@
+ <% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %> + <% if (activeNote.noteId === note.noteId) { %> - <%= note.title %> + <%= titleWithPrefix %> <% } else { %> - <%= note.title %> + <%= titleWithPrefix %> <% } %>
<% if (note.hasChildren()) { %>