127 lines
4.2 KiB
Plaintext
Executable File
127 lines
4.2 KiB
Plaintext
Executable File
<%
|
||
var proj;
|
||
if (page.layout === 'wiki' && page.wiki) {
|
||
proj = theme.wiki.projects[page.wiki];
|
||
}
|
||
// 默认组件
|
||
if (page.sidebar == undefined) {
|
||
if (page.layout == 'post' && page.content) {
|
||
page.sidebar = theme.sidebar.widgets.post;
|
||
} else if (page.layout == 'wiki' && page.content && page.wiki) {
|
||
let proj = theme.wiki.projects[page.wiki];
|
||
if (proj.sidebar) {
|
||
page.sidebar = proj.sidebar;
|
||
} else {
|
||
page.sidebar = theme.sidebar.widgets.wiki;
|
||
}
|
||
} else if (is_home() || ['categories', 'tags', 'archives', 'index', '404', undefined].includes(page.layout)) {
|
||
page.sidebar = theme.sidebar.widgets.index;
|
||
} else if (page.layout == 'page') {
|
||
page.sidebar = theme.sidebar.widgets.page;
|
||
} else {
|
||
page.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[0].trim() + '</div>';
|
||
el += '<div class="sub hover cap" style="opacity:0">' + arr[1].trim() + '</div>';
|
||
} else if (arr.length > 0) {
|
||
el += '<div class="sub cap">' + arr[0] + '</div>';
|
||
}
|
||
}
|
||
el += '</a>';
|
||
return el;
|
||
}
|
||
function layoutWidgets() {
|
||
var el = '';
|
||
el += '<div class="widgets">';
|
||
if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') {
|
||
el += '<div class="widget-wrap logo-wrap wiki"><div class="widget-body">';
|
||
// all products
|
||
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(config.wiki_dir) + '">';
|
||
el += '<svg aria-hidden="true" viewBox="0 0 16 16" width="1rem" height="1rem" 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.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
|
||
proj = {
|
||
path: md_link(theme.sidebar.menu[page.menu_id]),
|
||
wiki: __(md_text(theme.sidebar.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></div>';
|
||
}
|
||
if (page.sidebar) {
|
||
page.sidebar.forEach((w, i) => {
|
||
if (w in theme.data.widgets) {
|
||
let widget = theme.data.widgets[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() %>
|