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

79 lines
2.1 KiB
Plaintext
Raw Normal View History

2024-02-05 10:03:55 +08:00
<%
const wiki = theme.wiki.tree[page.wiki]
const topic = theme.topic.tree[page.topic]
if (page.rightbar == null) {
const { site_tree } = theme
var sidebar
if (is_home()) {
sidebar = site_tree.home.rightbar
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
sidebar = site_tree.index_blog.rightbar
} else if (page.layout === 'index_topic') {
// 专栏列表页等同于博客列表页
sidebar = site_tree.index_blog.rightbar
} else if (page.topic?.length > 0) {
// 专栏文章内页等同于普通文章内页
sidebar = site_tree.post.rightbar
} else if (page.layout === 'index_wiki') {
sidebar = site_tree.index_wiki.rightbar
} else if (page.wiki?.length > 0) {
sidebar = site_tree.wiki.rightbar
} else if (page.layout === '404') {
sidebar = site_tree.error_page.rightbar
} else if (page.layout === 'page') {
sidebar = site_tree.page.rightbar
} else if (page.layout === 'post') {
sidebar = site_tree.post.rightbar
} else if (page.layout == null) {
sidebar = site_tree.page.rightbar
} else {
sidebar = []
}
if (topic?.rightbar) {
sidebar = topic.rightbar
}
if (wiki?.rightbar) {
sidebar = wiki.rightbar
}
page.rightbar = sidebar
}
// parse array string
if (typeof page.rightbar == 'string') {
page.rightbar = page.rightbar.replace(/ /g, '').split(',');
}
function layoutWidgets() {
var el = '';
el += '<div class="widgets">';
if (page.rightbar) {
page.rightbar.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.widgets) {
Object.assign(widget, theme.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;
}
%>
<%- layoutWidgets() %>