2021-02-19 23:33:19 +08:00
|
|
|
<%
|
2024-01-19 01:05:44 +08:00
|
|
|
|
|
|
|
const wiki = theme.wiki.tree[page.wiki]
|
|
|
|
const topic = theme.topic.tree[page.topic]
|
|
|
|
|
2024-01-14 16:42:20 +08:00
|
|
|
if (page.sidebar == null) {
|
2024-01-14 17:21:19 +08:00
|
|
|
const { site_tree } = theme
|
2024-01-14 16:42:20 +08:00
|
|
|
var sidebar
|
|
|
|
if (is_home()) {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.home.sidebar
|
2022-11-29 22:25:02 +08:00
|
|
|
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
|
2024-01-20 01:51:09 +08:00
|
|
|
sidebar = site_tree.index_blog.sidebar
|
2024-01-17 14:07:30 +08:00
|
|
|
} else if (page.layout === 'index_topic') {
|
|
|
|
// 专栏列表页等同于博客列表页
|
2024-01-20 01:51:09 +08:00
|
|
|
sidebar = site_tree.index_blog.sidebar
|
2024-01-18 22:11:58 +08:00
|
|
|
} else if (page.topic?.length > 0) {
|
2024-01-20 01:51:09 +08:00
|
|
|
// 专栏文章内页等同于普通文章内页
|
|
|
|
sidebar = site_tree.post.sidebar
|
|
|
|
} else if (page.layout === 'index_wiki') {
|
|
|
|
sidebar = site_tree.index_wiki.sidebar
|
|
|
|
} else if (page.wiki?.length > 0) {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.wiki.sidebar
|
2024-01-14 16:42:20 +08:00
|
|
|
} else if (page.layout === '404') {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.error_page.sidebar
|
2024-01-14 17:04:00 +08:00
|
|
|
} else if (page.layout === 'page') {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.page.sidebar
|
2024-01-14 17:04:00 +08:00
|
|
|
} else if (page.layout === 'post') {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.post.sidebar
|
2024-01-14 17:04:00 +08:00
|
|
|
} else if (page.layout == null) {
|
2024-01-14 17:21:19 +08:00
|
|
|
sidebar = site_tree.page.sidebar
|
2021-02-19 23:33:19 +08:00
|
|
|
} else {
|
2024-01-14 16:42:20 +08:00
|
|
|
sidebar = []
|
|
|
|
}
|
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
if (topic?.sidebar) {
|
|
|
|
sidebar = topic.sidebar
|
2024-01-14 16:42:20 +08:00
|
|
|
}
|
2024-01-19 01:05:44 +08:00
|
|
|
if (wiki?.sidebar) {
|
|
|
|
sidebar = wiki.sidebar
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2024-01-17 00:27:48 +08:00
|
|
|
|
2024-01-14 16:42:20 +08:00
|
|
|
page.sidebar = sidebar
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2022-11-19 02:24:53 +08:00
|
|
|
|
2024-01-19 01:05:44 +08:00
|
|
|
|
2022-11-19 02:24:53 +08:00
|
|
|
// parse array string
|
|
|
|
if (typeof page.sidebar == 'string') {
|
|
|
|
page.sidebar = page.sidebar.replace(/ /g, '').split(',');
|
|
|
|
}
|
2022-11-19 16:48:44 +08:00
|
|
|
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) {
|
2022-12-09 23:56:58 +08:00
|
|
|
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>';
|
2022-11-19 16:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
el += '</a>';
|
|
|
|
return el;
|
|
|
|
}
|
2021-07-04 22:53:55 +08:00
|
|
|
function layoutWidgets() {
|
|
|
|
var el = '';
|
|
|
|
el += '<div class="widgets">';
|
|
|
|
if (page.sidebar) {
|
|
|
|
page.sidebar.forEach((w, i) => {
|
2022-11-22 22:38:01 +08:00
|
|
|
let name = ''
|
2022-11-22 23:08:30 +08:00
|
|
|
let widget = {}
|
2022-11-22 22:38:01 +08:00
|
|
|
if (typeof w == 'string') {
|
|
|
|
name = w
|
2022-11-22 23:08:30 +08:00
|
|
|
} else if (typeof w == 'object' && w.override) {
|
2022-11-22 22:38:01 +08:00
|
|
|
name = w.override
|
|
|
|
}
|
2024-01-19 01:05:44 +08:00
|
|
|
if (name in theme.widgets) {
|
|
|
|
Object.assign(widget, theme.widgets[name])
|
2022-11-22 22:38:01 +08:00
|
|
|
}
|
2022-11-29 21:54:15 +08:00
|
|
|
if (typeof w == 'object' && (w.override || w.layout)) {
|
2022-11-22 22:38:01 +08:00
|
|
|
Object.assign(widget, w)
|
|
|
|
}
|
|
|
|
if (widget && widget.layout) {
|
2022-11-23 21:54:21 +08:00
|
|
|
el += partial('../widgets/' + widget.layout, {item: widget})
|
2021-07-04 22:53:55 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
el += '</div>';
|
|
|
|
return el;
|
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
function layoutFooterDiv() {
|
2024-01-17 22:57:52 +08:00
|
|
|
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"';
|
2021-07-14 14:54:06 +08:00
|
|
|
}
|
2024-01-17 22:57:52 +08:00
|
|
|
} else if (item.onclick) {
|
|
|
|
item.onclick = item.onclick.replace(/"|\'/g, '"');
|
|
|
|
el += ' onclick="' + item.onclick + '"';
|
2021-07-04 21:29:06 +08:00
|
|
|
}
|
2024-01-17 22:57:52 +08:00
|
|
|
el += '>';
|
2024-01-30 18:08:47 +08:00
|
|
|
el += icon(item.icon, 'no-lazy')
|
2024-01-17 22:57:52 +08:00
|
|
|
el += '</a>';
|
2021-11-19 20:37:42 +08:00
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2024-01-17 22:57:52 +08:00
|
|
|
el += '</div>';
|
|
|
|
el += '</footer>';
|
|
|
|
return el;
|
2021-02-19 23:33:19 +08:00
|
|
|
}
|
2024-01-14 16:42:20 +08:00
|
|
|
|
2024-01-17 00:27:48 +08:00
|
|
|
function layoutLogo() {
|
2024-01-17 14:07:30 +08:00
|
|
|
return partial('logo', {where: 'sidebar'})
|
2024-01-17 00:27:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function layoutNavArea() {
|
|
|
|
var search = {}
|
|
|
|
if (page.search) {
|
|
|
|
search = page.search
|
2024-01-19 01:05:44 +08:00
|
|
|
} else if (wiki?.search) {
|
|
|
|
search = wiki.search
|
|
|
|
} else if (topic?.search) {
|
|
|
|
search = topic.search
|
2024-01-17 00:27:48 +08:00
|
|
|
}
|
|
|
|
var el = ''
|
|
|
|
el += `<div class="nav-area">`
|
|
|
|
el += partial('search', {item: search})
|
|
|
|
el += partial('menu', {where: 'sidebar'})
|
|
|
|
el += `</div>`
|
|
|
|
return el
|
|
|
|
}
|
2021-02-19 23:33:19 +08:00
|
|
|
%>
|
2024-01-17 00:27:48 +08:00
|
|
|
<%- layoutLogo() %>
|
|
|
|
<%- layoutNavArea() %>
|
2021-07-04 22:53:55 +08:00
|
|
|
<%- layoutWidgets() %>
|
2021-03-05 21:37:28 +08:00
|
|
|
<%- layoutFooterDiv() %>
|