hexo-theme-stellar/layout/_partial/sidebar/widgets/toc.ejs

75 lines
2.2 KiB
Plaintext

<%
var enable = false;
if (page.layout == 'post') {
if (page.content && toc(page.content).length > 0) {
enable = true;
}
} else if (page.layout == 'wiki' || page.sidebar.includes('toc') == true) {
enable = true;
}
function layout_toc() {
if (toc(page.content).length > 0) {
return toc(page.content, {
list_number: item.list_number,
min_depth: item.min_depth,
max_depth: item.max_depth
});
}
}
%>
<% if (enable == true) { %>
<div class='widget-wrap' id='toc'>
<div class='widget-header h4 dis-select'>
<span class='name'>
<% if (page.toc_title) { %>
<%- page.toc_title %>
<% } else if (page.layout == 'wiki') { %>
<%- page.wiki || item.wiki %>
<% } else { %>
<%- __('meta.toc') %>
<% } %>
</span>
</div>
<div class='widget-body fs14 <%- page.layout == "wiki" ? "wiki" : "post" %>'>
<% if (page.layout == 'wiki' && page.wiki) { %>
<%
var wikis = [];
wikis = site.pages.filter(function (p) {
if (p.layout == 'wiki' && p.wiki && p.wiki == page.wiki && (p.title || p.seo_title)) {
if (p.order == undefined) {
p.order = 0;
}
return true;
} else {
return false;
}
}).sort('order');
%>
<% if (wikis.length > 1) { %>
<% wikis.each(function(p) { %>
<% if (p.path == page.path) { %>
<div class='doc-tree active'>
<a class='doc-tree-link active' href="<%- url_for(p.path) %>"><span class="toc-text"><%- p.title || p.seo_title %></span></a>
<%- layout_toc() %>
</div>
<% } else { %>
<div class='doc-tree'>
<a class='doc-tree-link' href="<%- url_for(p.path) %>"><span class="toc-text"><%- p.title || p.seo_title %></span></a>
</div>
<% } %>
<% }); %>
<% } else { %>
<div class='doc-tree active'>
<%- layout_toc() %>
</div>
<% } %>
<% } else { %>
<div class='doc-tree active'>
<%- layout_toc() %>
</div>
<% } %>
</div>
</div>
<% } %>