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

88 lines
2.3 KiB
Plaintext

<%
function layoutToc() {
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
});
}
return '';
}
function layoutDiv(fallback) {
var t = '';
if (page.layout == 'post' && page.content) {
let toc_content = toc(page.content);
if (toc_content && toc_content.length > 0) {
t = page.layout;
}
} else if (page.layout == 'wiki') {
t = page.layout;
} else if (page.sidebar.includes('toc') == true) {
t = page.layout;
}
var el = '';
if (t.length > 0) {
el += '<div class="widget-wrap" id="toc">';
el += '<div class="widget-header h4 dis-select">';
if (page.toc_title) {
el += '<span class="name">' + page.toc_title + '</span>';
} else if (t == 'wiki') {
el += '';
} else {
el += '<span class="name">' + __("meta.toc") + '</span>';
}
el += '</div>';
el += '<div class="widget-body fs14 ' + t + '">';
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) {
let isActive = '';
if (p.path == page.path) {
isActive += ' active';
}
el += '<div class="doc-tree' + isActive + '">';
el += '<a class="doc-tree-link' + isActive + '" href="' + url_for(p.path) + '">';
el += '<span class="toc-text">' + (p.title || p.seo_title) + '</span>';
el += '</a>';
if (p.path == page.path) {
el += layoutToc();
}
el += '</div>';
});
} else {
el += '<div class="doc-tree active">';
el += layoutToc();
el += '</div>';
}
} else {
el += '<div class="doc-tree active">';
el += layoutToc();
el += '</div>';
}
el += '</div>';
el += '</div>';
return el;
} else if (item.fallback) {
return fallback(item.fallback);
}
}
%>
<%-
layoutDiv(function(widget){
return partial(widget, {item: theme.sidebar.widgets[widget]})
})
%>