2021-02-19 23:33:19 +08:00
|
|
|
<%
|
2024-01-19 01:05:44 +08:00
|
|
|
const proj = theme.wiki.tree[page.wiki]
|
2024-01-14 01:39:02 +08:00
|
|
|
var hasTOC = true
|
|
|
|
function layoutTocBody() {
|
2021-02-19 23:33:19 +08:00
|
|
|
if (toc(page.content).length > 0) {
|
2024-01-13 21:10:26 +08:00
|
|
|
hasTOC = true
|
2021-02-19 23:33:19 +08:00
|
|
|
return toc(page.content, {
|
|
|
|
list_number: item.list_number,
|
|
|
|
min_depth: item.min_depth,
|
|
|
|
max_depth: item.max_depth
|
|
|
|
});
|
|
|
|
}
|
2024-01-13 21:10:26 +08:00
|
|
|
hasTOC = false
|
|
|
|
return ''
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2021-07-25 22:47:18 +08:00
|
|
|
|
|
|
|
function layoutTocHeader(title) {
|
2024-01-14 01:39:02 +08:00
|
|
|
var el = ''
|
2024-01-17 22:57:52 +08:00
|
|
|
el += `<div class="widget-header dis-select">`
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `<span class="name">${title || __("meta.toc")}</span>`
|
|
|
|
el += `</div>`
|
|
|
|
return el
|
2021-07-25 22:47:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function layoutDocTree(pages) {
|
2024-01-14 01:39:02 +08:00
|
|
|
var el = ''
|
2023-12-06 13:22:07 +08:00
|
|
|
for (let p of pages) {
|
|
|
|
if (p.title == null || p.title.length == 0) {
|
2024-01-14 01:39:02 +08:00
|
|
|
continue
|
2023-12-06 13:22:07 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
let isActive = ''
|
2021-07-25 22:47:18 +08:00
|
|
|
if (p.path === page.path) {
|
2024-01-14 01:39:02 +08:00
|
|
|
isActive += ' active'
|
2021-07-25 22:47:18 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `<div class="doc-tree${isActive}">`
|
2021-07-25 22:47:18 +08:00
|
|
|
if (proj.pages.length > 1) {
|
2022-11-19 16:48:44 +08:00
|
|
|
let href = url_for(p.path);
|
2022-11-19 23:03:52 +08:00
|
|
|
if (p.is_homepage) {
|
2022-11-19 16:48:44 +08:00
|
|
|
href += '#start'
|
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `<a class="doc-tree-link${isActive}" href="${href}">`
|
|
|
|
el += `<span class="toc-text">${p.title}</span>`
|
2024-01-17 00:27:48 +08:00
|
|
|
if (isActive.length > 0) {
|
2024-01-19 13:51:55 +08:00
|
|
|
el += icon('default:bookmark')
|
2024-01-17 00:27:48 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `</a>`
|
2021-07-25 22:47:18 +08:00
|
|
|
}
|
|
|
|
if (p.path === page.path) {
|
2024-01-14 01:39:02 +08:00
|
|
|
el += layoutTocBody()
|
2021-07-25 22:47:18 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `</div>`
|
2023-12-06 13:22:07 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
return el
|
2021-07-25 22:47:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-07 21:34:11 +08:00
|
|
|
function layoutDiv(fallback) {
|
2024-01-14 01:39:02 +08:00
|
|
|
var type = ''
|
2024-01-19 01:05:44 +08:00
|
|
|
if (proj?.pages) {
|
|
|
|
type = proj.pages.length > 1 ? 'multi' : 'single'
|
2021-07-25 22:47:18 +08:00
|
|
|
} else {
|
2024-01-14 01:39:02 +08:00
|
|
|
let toc_content = toc(page.content)
|
2021-04-07 21:34:11 +08:00
|
|
|
if (toc_content && toc_content.length > 0) {
|
2024-01-14 01:39:02 +08:00
|
|
|
type = 'single'
|
2021-04-07 21:34:11 +08:00
|
|
|
}
|
|
|
|
}
|
2021-07-25 22:47:18 +08:00
|
|
|
|
2024-01-14 01:39:02 +08:00
|
|
|
var el = ''
|
2021-07-25 22:47:18 +08:00
|
|
|
if (type.length > 0) {
|
2024-01-19 01:05:44 +08:00
|
|
|
el += `<widget class="widget-wrapper${scrollreveal(' ')} toc ${type}" id="data-toc" collapse="${item.collapse}">`
|
|
|
|
if (proj) {
|
2021-07-25 22:47:18 +08:00
|
|
|
// wiki 布局
|
2023-12-06 13:22:07 +08:00
|
|
|
if (proj.sections && proj.sections.length > 0 && proj.pages.length > 1) { // 多 pages
|
2023-12-20 12:17:35 +08:00
|
|
|
for (let sec of proj.sections) {
|
|
|
|
if (sec.pages.length == 0) {
|
2024-01-14 01:39:02 +08:00
|
|
|
continue
|
2023-12-20 12:17:35 +08:00
|
|
|
}
|
2023-12-06 13:20:04 +08:00
|
|
|
if (sec.title?.length > 0) {
|
2024-01-14 01:39:02 +08:00
|
|
|
el += layoutTocHeader(sec.title)
|
2023-12-06 13:20:04 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `<div class="widget-body fs14">`
|
|
|
|
el += layoutDocTree(sec.pages)
|
|
|
|
el += `</div>`
|
2023-12-20 12:17:35 +08:00
|
|
|
}
|
2023-12-06 13:22:07 +08:00
|
|
|
} else { // 单 page
|
2023-11-28 17:41:52 +08:00
|
|
|
if (proj.pages.length == 1) {
|
2024-01-18 12:16:41 +08:00
|
|
|
el += layoutTocHeader()
|
2024-01-14 01:39:02 +08:00
|
|
|
}
|
|
|
|
el += `<div class="widget-body fs14">`
|
|
|
|
el += layoutDocTree(proj.pages)
|
|
|
|
el += `</div>`
|
|
|
|
if (hasTOC == false) {
|
|
|
|
return ''
|
2023-11-28 17:41:52 +08:00
|
|
|
}
|
2021-04-07 21:34:11 +08:00
|
|
|
}
|
2024-01-19 01:05:44 +08:00
|
|
|
} else {
|
|
|
|
// post 布局
|
|
|
|
el += layoutTocHeader()
|
|
|
|
el += `<div class="widget-body fs14">`
|
|
|
|
el += `<div class="doc-tree active">`
|
|
|
|
el += layoutTocBody()
|
|
|
|
el += `</div>`
|
|
|
|
el += `</div>`
|
|
|
|
if (hasTOC == false) {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
el += `</widget>`
|
2021-04-07 21:34:11 +08:00
|
|
|
} else if (item.fallback) {
|
2024-01-19 01:05:44 +08:00
|
|
|
const fallback = theme.widgets[item.fallback]
|
2024-01-17 00:27:48 +08:00
|
|
|
el += partial(fallback.layout, {item: fallback})
|
2021-04-07 21:34:11 +08:00
|
|
|
}
|
2024-01-14 01:39:02 +08:00
|
|
|
return el
|
2021-04-07 21:34:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
%>
|
2021-07-25 22:47:18 +08:00
|
|
|
|
|
|
|
<%- layoutDiv() %>
|