Skip to content

Build your personal knowledge base with Trilium Notes

fix(share): crash if sharing single note without tree

Elian Doran3b81d00de73d
diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejs
index a8c5722e24..991ba5d0c3 100644
--- a/packages/share-theme/src/templates/page.ejs
+++ b/packages/share-theme/src/templates/page.ejs
@@ -100,6 +100,7 @@ const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark";
const headingRe = /(<h[1-6]>)(.+?)(<\/h[1-6]>)/g;
const headingMatches = [...content.matchAll(headingRe)];
const slugify = (text) => text.toLowerCase().replace(/[^\w]/g, "-");
+const hasTree = subRoot.note.hasVisibleChildren();
content = content.replaceAll(headingRe, (...match) => {
match[0] = match[0].replace(match[3], `<a id="${slugify(match[2])}" class="toc-anchor" name="${slugify(match[2])}" href="#${slugify(match[2])}">#</a>${match[3]}`);
return match[0];
@@ -135,7 +136,7 @@ content = content.replaceAll(headingRe, (...match) => {
<input type="text" class="search-input" placeholder="Search...">
</div>
</div>
- <% if (subRoot.note.hasVisibleChildren()) { %>
+ <% if (hasTree) { %>
<nav id="menu">
<%
const ancestors = [];
@@ -198,7 +199,9 @@ content = content.replaceAll(headingRe, (...match) => {
</div>
<% } %>
- <%- include("prev_next", { note: note, subRoot: subRoot }) %>
+ <% if (hasTree) { %>
+ <%- include("prev_next", { note: note, subRoot: subRoot }) %>
+ <% } %>
</footer>
</div>
<%