2021-02-19 23:33:19 +08:00
|
|
|
|
<%
|
|
|
|
|
// 默认组件
|
|
|
|
|
if (page.sidebar == undefined) {
|
|
|
|
|
if (page.layout == 'post' && page.content) {
|
2022-10-20 21:34:54 +08:00
|
|
|
|
page.sidebar = theme.sidebar.widgets.post;
|
2024-01-05 19:43:39 +08:00
|
|
|
|
} else if (page.layout == 'wiki' && page.wiki) {
|
2023-12-06 13:20:04 +08:00
|
|
|
|
let proj = theme.wiki.tree[page.wiki];
|
|
|
|
|
if (proj?.sidebar) {
|
2021-07-25 22:47:18 +08:00
|
|
|
|
page.sidebar = proj.sidebar;
|
|
|
|
|
} else {
|
2022-10-20 21:34:54 +08:00
|
|
|
|
page.sidebar = theme.sidebar.widgets.wiki;
|
2021-07-25 22:47:18 +08:00
|
|
|
|
}
|
2024-01-14 14:10:36 +08:00
|
|
|
|
} else if (page.layout === 'topic') {
|
|
|
|
|
if (page.topic && theme.topic?.tree[page.topic]?.sidebar) {
|
|
|
|
|
page.sidebar = theme.topic.tree[page.topic].sidebar;
|
|
|
|
|
} else {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.topic;
|
|
|
|
|
}
|
|
|
|
|
} else if (page.layout === 'index_topic') {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.index_topic
|
2022-11-29 22:25:02 +08:00
|
|
|
|
} else if (is_home()) {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.home;
|
|
|
|
|
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.blog_index;
|
|
|
|
|
} else if (['wiki_index'].includes(page.layout)) {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.wiki_index;
|
|
|
|
|
} else if (['404', undefined].includes(page.layout)) {
|
|
|
|
|
page.sidebar = theme.sidebar.widgets.others;
|
2021-11-19 22:04:14 +08:00
|
|
|
|
} else if (page.layout == 'page') {
|
2022-10-20 21:34:54 +08:00
|
|
|
|
page.sidebar = theme.sidebar.widgets.page;
|
2021-02-19 23:33:19 +08:00
|
|
|
|
} else {
|
2021-11-19 22:04:14 +08:00
|
|
|
|
page.sidebar = [];
|
2021-02-19 23:33:19 +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">';
|
2022-11-19 16:48:44 +08:00
|
|
|
|
if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') {
|
2022-11-23 21:54:21 +08:00
|
|
|
|
el += '<widget class="widget-wrapper logo-wrap wiki"><div class="widget-body">';
|
2022-11-19 16:48:44 +08:00
|
|
|
|
// all products
|
|
|
|
|
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(config.wiki_dir) + '">';
|
2023-12-21 23:59:53 +08:00
|
|
|
|
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>';
|
2022-11-19 16:48:44 +08:00
|
|
|
|
el += __('btn.all_wiki');
|
|
|
|
|
el += '</a>';
|
|
|
|
|
// this product
|
2024-01-14 14:10:36 +08:00
|
|
|
|
var proj;
|
|
|
|
|
if (page.layout === 'wiki' && page.wiki) {
|
|
|
|
|
proj = theme.wiki.tree[page.wiki];
|
|
|
|
|
}
|
2022-11-19 16:48:44 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-11-23 21:54:21 +08:00
|
|
|
|
el += '</div></widget>';
|
2022-11-19 16:48:44 +08:00
|
|
|
|
}
|
2021-07-04 22:53:55 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
if (name in theme.data.widgets) {
|
|
|
|
|
Object.assign(widget, theme.data.widgets[name])
|
|
|
|
|
}
|
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() {
|
2021-11-19 20:37:42 +08:00
|
|
|
|
if (page.layout !== 'wiki' && theme.footer.social) {
|
2021-07-04 21:29:06 +08:00
|
|
|
|
var el = '<footer class="footer dis-select">';
|
2021-07-14 14:54:06 +08:00
|
|
|
|
el += '<div class="social-wrap">';
|
2021-11-19 20:37:42 +08:00
|
|
|
|
for (let id of Object.keys(theme.footer.social)) {
|
|
|
|
|
let item = theme.footer.social[id];
|
2021-07-14 14:54:06 +08:00
|
|
|
|
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 + '"';
|
|
|
|
|
}
|
2021-07-04 22:53:55 +08:00
|
|
|
|
el += '>';
|
2021-07-14 14:54:06 +08:00
|
|
|
|
el += item.icon;
|
2021-07-04 22:53:55 +08:00
|
|
|
|
el += '</a>';
|
2021-07-04 21:29:06 +08:00
|
|
|
|
}
|
2021-11-19 20:37:42 +08:00
|
|
|
|
}
|
2021-07-14 14:54:06 +08:00
|
|
|
|
el += '</div>';
|
2021-07-04 21:29:06 +08:00
|
|
|
|
el += '</footer>';
|
2021-02-19 23:33:19 +08:00
|
|
|
|
return el;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%>
|
2022-10-05 23:00:52 +08:00
|
|
|
|
<% if (page.header == undefined || page.header == 'left' || page.header == 'auto') { %>
|
|
|
|
|
<%- partial('header', {where: 'sidebar'}) %>
|
|
|
|
|
<% } %>
|
2021-07-04 22:53:55 +08:00
|
|
|
|
<%- layoutWidgets() %>
|
2021-03-05 21:37:28 +08:00
|
|
|
|
<%- layoutFooterDiv() %>
|