hexo-theme-stellar/layout/_partial/widgets/tree.ejs

72 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2024-02-05 10:03:55 +08:00
<%
const proj = theme.wiki.tree[page.wiki]
function layoutTocHeader(title) {
var el = ''
el += `<div class="widget-header dis-select">`
el += `<span class="name">${title || __("meta.toc")}</span>`
el += `</div>`
return el
}
function layoutDocTree(pages) {
var el = ''
for (let p of pages) {
if (p.title == null || p.title.length == 0) {
continue
}
let isActive = ''
if (p.path === page.path) {
isActive += ' active'
}
if (proj.pages.length > 1) {
let href = url_for(p.path);
if (p.is_homepage) {
href += '#start'
}
el += `<a class="link${isActive}" href="${href}">`
el += `<span class="toc-text">${p.title}</span>`
if (isActive.length > 0) {
el += icon('default:bookmark.active')
}
el += `</a>`
}
}
return el
}
function layoutDiv(fallback) {
if (proj == null) {
return ''
}
if (proj.pages == null || proj.pages.length == 0) {
return ''
}
if (proj.sections == null || proj.sections.length == 0) {
return ''
}
var el = ''
for (let sec of proj.sections) {
if (sec.pages.length == 0) {
continue
}
if (sec.title?.length > 0) {
el += layoutTocHeader(sec.title)
}
2024-02-06 23:39:51 +08:00
const docTree = layoutDocTree(sec.pages)
if (docTree.trim().length > 0) {
el += `<div class="widget-body fs14">${docTree}</div>`
}
}
if (el.trim().length > 0) {
return `<widget class="widget-wrapper${scrollreveal(' ')} post-list">${el}</widget>`
} else {
return ''
2024-02-05 10:03:55 +08:00
}
}
%>
<%- layoutDiv() %>