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

This commit is contained in:
Elian Doran 2025-06-09 20:52:02 +03:00
parent dd6660a6cd
commit 3b81d00de7
No known key found for this signature in database

View File

@ -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>
<% } %>
<% if (hasTree) { %>
<%- include("prev_next", { note: note, subRoot: subRoot }) %>
<% } %>
</footer>
</div>
<%