hexo-theme-stellar/layout/_partial/sidebar/index.ejs

154 lines
4.3 KiB
Plaintext
Executable File

<%
if (page.sidebar == null) {
const { site_tree } = theme
var sidebar
if (is_home()) {
sidebar = site_tree.home.sidebar
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
sidebar = site_tree.blog.sidebar
} else if (page.layout === 'index_topic') {
// 专栏列表页等同于博客列表页
sidebar = site_tree.blog.sidebar
} else if (page.layout === 'topic') {
sidebar = site_tree.topic.sidebar
} else if (page.layout === 'index_wiki' || page.layout === 'wiki') {
sidebar = site_tree.wiki.sidebar
} else if (page.layout === '404') {
sidebar = site_tree.error_page.sidebar
} else if (page.layout === 'page') {
sidebar = site_tree.page.sidebar
} else if (page.layout === 'post') {
sidebar = site_tree.post.sidebar
} else if (page.layout == null) {
sidebar = site_tree.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.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() {
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, '&quot;');
el += ' onclick="' + item.onclick + '"';
}
el += '>';
el += item.icon;
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 (page.wiki && page.layout == 'wiki' && theme.wiki.tree[page.wiki]) {
const proj = theme.wiki.tree[page.wiki]
if (proj.search) {
search = proj.search
}
} else if (page.topic && page.layout == 'topic' && theme.topic.tree[page.topic]) {
const topic = theme.topic.tree[page.topic]
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() %>