151 lines
4.9 KiB
Plaintext
Executable File
151 lines
4.9 KiB
Plaintext
Executable File
<%
|
||
if (page.sidebar == null) {
|
||
const root = theme.root
|
||
var sidebar
|
||
if (is_home()) {
|
||
sidebar = root.home.sidebar
|
||
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
|
||
sidebar = root.blog.sidebar
|
||
} else if (page.layout === 'index_topic' || page.layout === 'topic') {
|
||
sidebar = root.topic.sidebar
|
||
} else if (page.layout === 'index_wiki' || page.layout === 'wiki') {
|
||
sidebar = root.wiki.sidebar
|
||
} else if (page.layout === '404') {
|
||
sidebar = root.error_page.sidebar
|
||
} else if (page.layout === 'page') {
|
||
sidebar = root.page.sidebar
|
||
} else if (page.layout === 'post') {
|
||
sidebar = root.post.sidebar
|
||
} else if (page.layout == null) {
|
||
sidebar = root.page.sidebar
|
||
} else {
|
||
sidebar = []
|
||
}
|
||
|
||
if (page.layout === 'topic' && page.topic && theme.topic?.tree[page.topic]?.sidebar) {
|
||
sidebar = theme.topic.tree[page.topic].sidebar
|
||
}
|
||
if (page.layout == 'wiki' && page.wiki && theme.wiki?.tree[page.wiki]?.sidebar) {
|
||
sidebar = theme.wiki.tree[page.wiki].sidebar
|
||
}
|
||
|
||
page.sidebar = sidebar
|
||
}
|
||
|
||
// parse array string
|
||
if (typeof page.sidebar == 'string') {
|
||
page.sidebar = page.sidebar.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 = '';
|
||
var proj;
|
||
if (page.layout === 'wiki' && page.wiki) {
|
||
proj = theme.wiki.tree[page.wiki];
|
||
}
|
||
el += '<div class="widgets">';
|
||
if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') {
|
||
el += '<widget class="widget-wrapper logo-wrap wiki"><div class="widget-body">';
|
||
// all products
|
||
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(theme.root.wiki.base_dir) + '">';
|
||
el += '<svg aria-hidden="true" viewBox="0 0 16 16" width="1.2em" height="1.2em" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>';
|
||
el += __('btn.all_wiki');
|
||
el += '</a>';
|
||
// this product
|
||
if (proj == undefined) {
|
||
// 如果没有项目名,则使用menu中显示的名字
|
||
if (page.menu_id && theme.menu[page.menu_id] && md_link(theme.menu[page.menu_id])) {
|
||
proj = {
|
||
path: md_link(theme.menu[page.menu_id]),
|
||
wiki: __(md_text(theme.menu[page.menu_id]))
|
||
};
|
||
}
|
||
}
|
||
if (proj != undefined) {
|
||
let main = proj.name || proj.title || page.wiki || page.title;
|
||
let url = proj.homepage.path;
|
||
let sub = proj.subtitle;
|
||
el += layoutTitle(main, url, sub);
|
||
}
|
||
el += '</div></widget>';
|
||
}
|
||
if (page.sidebar) {
|
||
page.sidebar.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.data.widgets) {
|
||
Object.assign(widget, theme.data.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() {
|
||
if (page.layout !== 'wiki' && theme.footer.social) {
|
||
var el = '<footer class="footer dis-select">';
|
||
el += '<div class="social-wrap">';
|
||
for (let id of Object.keys(theme.footer.social)) {
|
||
let item = theme.footer.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 += item.icon;
|
||
el += '</a>';
|
||
}
|
||
}
|
||
el += '</div>';
|
||
el += '</footer>';
|
||
return el;
|
||
} else {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
%>
|
||
<% if (page.header == undefined || page.header == 'left' || page.header == 'auto') { %>
|
||
<%- partial('header', {where: 'sidebar'}) %>
|
||
<% } %>
|
||
<%- layoutWidgets() %>
|
||
<%- layoutFooterDiv() %>
|