<% const linkClass = `type-${note.type}` + (activeNote.noteId === note.noteId ? " active" : ""); // 根据 note 类型和是否为当前激活的 note 来设置链接的类名 const isExternalLink = note.hasLabel("shareExternal"); // 检查 note 是否有 "shareExternal" 标签,确定是否是外部链接 const linkHref = isExternalLink ? note.getLabelValue("shareExternal") : `./${note.shareId}`; // 如果是外部链接,使用 "shareExternal" 标签的值,否则使用内部链接 const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : ""; // 如果是外部链接,设置 target 属性为 "_blank" 并加上安全属性 %> <% if (note.noteId !== subRoot.note.noteId) { %> <!-- 如果当前 note 不是根节点,创建一个链接 --> <a class="<%= linkClass %>" href="<%= linkHref %>"<%= target %>> <!-- 如果当前 note 有可见的子项,显示一个展开/折叠按钮 --> <% if (note.hasVisibleChildren()) { %><button class="collapse-button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></svg></button><% } %> <!-- 显示 note 的标题 --> <span><%= note.title %></span> </a> <% } %> <!-- 如果当前 note 有可见的子项,递归渲染子项 --> <% if (note.hasVisibleChildren()) { %> <ul> <!-- 遍历当前 note 的所有可见子项,并递归渲染每个子项 --> <% note.getVisibleChildNotes().forEach(function (childNote) { %> <% const hasChildren = childNote.hasVisibleChildren(); // 检查子项是否有可见的子项 const isAncestorOfActive = ancestors.some(p => p === childNote.noteId); // 判断子项是否是当前激活项的祖先 const expandedClass = isAncestorOfActive ? " expanded" : ""; // 如果是当前激活项的祖先,给它添加 "expanded" 类 %> <li class="<% if (hasChildren) { %>submenu-<% } %>item<%= expandedClass %>"> <!-- 递归渲染子项的内容,传递当前子项和根节点 --> <%- include('tree_item', {note: childNote, subRoot: subRoot}) %> </li> <% }) %> </ul> <% } %>