103 lines
2.4 KiB
Plaintext
103 lines
2.4 KiB
Plaintext
<%
|
|
let proj = theme.wiki.projects[page.wiki];
|
|
|
|
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 layoutTocHeader(title) {
|
|
var el = '';
|
|
el += '<div class="widget-header cap dis-select">';
|
|
if (title) {
|
|
el += '<span class="name">' + title + '</span>';
|
|
} else {
|
|
el += '<span class="name">' + __("meta.toc") + '</span>';
|
|
}
|
|
el += '</div>';
|
|
return el;
|
|
}
|
|
|
|
function layoutDocTree(pages) {
|
|
var el = '';
|
|
pages.forEach((p, i) => {
|
|
let isActive = '';
|
|
if (p.path === page.path) {
|
|
isActive += ' active';
|
|
}
|
|
el += '<div class="doc-tree' + isActive + '">';
|
|
if (proj.pages.length > 1) {
|
|
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>';
|
|
});
|
|
return el;
|
|
}
|
|
|
|
|
|
function layoutDiv(fallback) {
|
|
var type = '';
|
|
if (proj && proj.pages) {
|
|
if (proj.pages.length > 1) {
|
|
type = 'multi';
|
|
} else {
|
|
type = 'single';
|
|
}
|
|
} else {
|
|
let toc_content = toc(page.content);
|
|
if (toc_content && toc_content.length > 0) {
|
|
type = 'single';
|
|
}
|
|
}
|
|
|
|
var el = '';
|
|
if (type.length > 0) {
|
|
el += '<div class="widget-wrap ' + type + '" id="toc">';
|
|
if (page.layout !== 'wiki') {
|
|
// post 布局
|
|
el += layoutTocHeader(page.toc_title);
|
|
el += '<div class="widget-body fs14">';
|
|
el += '<div class="doc-tree active">';
|
|
el += layoutToc();
|
|
el += '</div>';
|
|
el += '</div>';
|
|
} else if (proj) {
|
|
// wiki 布局
|
|
if (proj.sections && proj.sections.length > 0) {
|
|
proj.sections.forEach((sec, i) => {
|
|
// 多 section
|
|
el += layoutTocHeader(sec.title);
|
|
el += '<div class="widget-body fs14">';
|
|
el += layoutDocTree(sec.pages);
|
|
el += '</div>';
|
|
});
|
|
} else {
|
|
// 单 section
|
|
el += layoutTocHeader(page.toc_title);
|
|
el += '<div class="widget-body fs14">';
|
|
el += layoutDocTree(proj.pages);
|
|
el += '</div>';
|
|
}
|
|
}
|
|
el += '</div>';
|
|
} else if (item.fallback) {
|
|
el += partial(item.fallback, {item: theme.data.widgets[item.fallback]});
|
|
}
|
|
return el;
|
|
}
|
|
|
|
%>
|
|
|
|
<%- layoutDiv() %>
|