164 lines
4.4 KiB
Plaintext
Executable File
164 lines
4.4 KiB
Plaintext
Executable File
<%
|
|
|
|
const wiki = theme.wiki.tree[page.wiki]
|
|
const topic = theme.topic.tree[page.topic]
|
|
const notebook = theme.notebooks.tree[page.notebook]
|
|
|
|
if (page.leftbar == null) {
|
|
const { site_tree } = theme
|
|
var sidebar
|
|
if (is_home()) {
|
|
sidebar = site_tree.home.leftbar
|
|
} else if (page.layout === 'notebooks') {
|
|
// 笔记本列表页
|
|
sidebar = site_tree.notebooks.leftbar
|
|
} else if (page.layout === 'notes') {
|
|
// 笔记列表页
|
|
sidebar = notebook ? notebook.leftbar : site_tree.notes.leftbar
|
|
} else if (notebook) {
|
|
// 笔记本文章内页
|
|
sidebar = page.leftbar ?? notebook.note_leftbar
|
|
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
|
|
sidebar = site_tree.index_blog.leftbar
|
|
} else if (page.layout === 'index_topic') {
|
|
// 专栏列表页等同于博客列表页
|
|
sidebar = site_tree.index_blog.leftbar
|
|
} else if (page.topic?.length > 0) {
|
|
// 专栏文章内页等同于普通文章内页
|
|
sidebar = site_tree.post.leftbar
|
|
} else if (page.layout === 'index_wiki') {
|
|
sidebar = site_tree.index_wiki.leftbar
|
|
} else if (page.wiki?.length > 0) {
|
|
sidebar = site_tree.wiki.leftbar
|
|
} else if (page.layout === '404') {
|
|
sidebar = site_tree.error_page.leftbar
|
|
} else if (page.layout === 'page') {
|
|
sidebar = site_tree.page.leftbar
|
|
} else if (page.layout === 'post') {
|
|
sidebar = site_tree.post.leftbar
|
|
} else if (page.layout == null) {
|
|
sidebar = site_tree.page.leftbar
|
|
} else {
|
|
sidebar = []
|
|
}
|
|
|
|
if (topic?.leftbar) {
|
|
sidebar = topic.leftbar
|
|
}
|
|
if (wiki?.leftbar) {
|
|
sidebar = wiki.leftbar
|
|
}
|
|
|
|
page.leftbar = sidebar
|
|
}
|
|
|
|
|
|
// parse array string
|
|
if (typeof page.leftbar == 'string') {
|
|
page.leftbar = page.leftbar.replace(/ /g, '').split(',');
|
|
}
|
|
|
|
|
|
function layoutTitle(main, url, sub) {
|
|
var el = '';
|
|
el += '<a class="title" href="' + url_for(url || "/") + '">';
|
|
el += '<div class="main" ff="title">' + main + '</div>';
|
|
if (sub) {
|
|
let arr = sub.split('|');
|
|
if (arr.length > 1) {
|
|
el += '<div class="sub normal cap">' + arr.shift().trim() + '</div>';
|
|
el += '<div class="sub hover cap" style="opacity:0">' + arr.join('|') + '</div>';
|
|
} else {
|
|
el += '<div class="sub cap">' + sub + '</div>';
|
|
}
|
|
}
|
|
el += '</a>';
|
|
return el;
|
|
}
|
|
function layoutWidgets() {
|
|
var el = '';
|
|
el += '<div class="widgets">';
|
|
if (page.leftbar) {
|
|
page.leftbar.forEach((w, i) => {
|
|
let name = ''
|
|
let widget = {}
|
|
if (typeof w == 'string') {
|
|
name = w
|
|
} else if (typeof w == 'object' && w.override) {
|
|
name = w.override
|
|
}
|
|
if (name in theme.widgets) {
|
|
Object.assign(widget, theme.widgets[name])
|
|
}
|
|
if (typeof w == 'object' && (w.override || w.layout)) {
|
|
Object.assign(widget, w)
|
|
}
|
|
if (widget && widget.layout) {
|
|
el += partial('../widgets/' + widget.layout, {item: widget})
|
|
}
|
|
});
|
|
}
|
|
el += '</div>';
|
|
return el;
|
|
}
|
|
function layoutFooterDiv() {
|
|
const { social } = theme.footer
|
|
if (social == null) {
|
|
return ''
|
|
}
|
|
var el = '<footer class="footer dis-select">';
|
|
el += '<div class="social-wrap">';
|
|
for (let id of Object.keys(social)) {
|
|
let item = social[id];
|
|
if (item.icon && (item.url || item.onclick)) {
|
|
el += '<a class="social"';
|
|
if (item.title) {
|
|
el += ' title="' + item.title + '"';
|
|
}
|
|
if (item.url) {
|
|
el += ' href="' + url_for(item.url) + '"';
|
|
if (item.url.includes('://')) {
|
|
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
|
|
} else {
|
|
el += ' rel="noopener noreferrer"';
|
|
}
|
|
} else if (item.onclick) {
|
|
item.onclick = item.onclick.replace(/"|\'/g, '"');
|
|
el += ' onclick="' + item.onclick + '"';
|
|
}
|
|
el += '>';
|
|
el += icon(item.icon, 'no-lazy')
|
|
el += '</a>';
|
|
}
|
|
}
|
|
el += '</div>';
|
|
el += '</footer>';
|
|
return el;
|
|
}
|
|
|
|
function layoutLogo() {
|
|
return partial('logo', {where: 'sidebar'})
|
|
}
|
|
|
|
function layoutNavArea() {
|
|
var search = {}
|
|
if (page.search) {
|
|
search = page.search
|
|
} else if (wiki?.search) {
|
|
search = wiki.search
|
|
} else if (topic?.search) {
|
|
search = topic.search
|
|
}
|
|
var el = ''
|
|
el += `<div class="nav-area">`
|
|
el += partial('search', {item: search})
|
|
el += partial('menu', {where: 'sidebar'})
|
|
el += `</div>`
|
|
return el
|
|
}
|
|
%>
|
|
<%- layoutLogo() %>
|
|
<%- layoutNavArea() %>
|
|
<%- layoutWidgets() %>
|
|
<%- layoutFooterDiv() %>
|