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

94 lines
2.6 KiB
Plaintext
Raw Permalink 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]
2024-05-13 09:45:38 +08:00
const notebook = theme.notebooks.tree[page.notebook]
2024-02-05 10:03:55 +08:00
if (page.rightbar == null) {
const { site_tree } = theme
var sidebar
if (is_home()) {
sidebar = site_tree.home.rightbar
2024-05-13 09:45:38 +08:00
} else if (page.layout === 'notebooks') {
// 笔记本列表页
sidebar = site_tree.notebooks.rightbar
} else if (page.layout === 'notes') {
// 笔记列表页
sidebar = notebook ? notebook.rightbar : site_tree.notes.rightbar
} else if (notebook) {
// 笔记本文章内页
sidebar = page.rightbar ?? notebook.note_rightbar
2024-02-05 10:03:55 +08:00
} 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() {
2024-02-06 23:39:51 +08:00
if (page.rightbar == null || page.rightbar.length == 0) {
return ''
}
var el = ''
2024-02-05 10:03:55 +08:00
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})
}
});
}
2024-02-06 23:39:51 +08:00
if (el.trim().length > 0) {
return `<div class="widgets">${el}</div>`
} else {
return ''
}
2024-02-05 10:03:55 +08:00
}
%>
<%- layoutWidgets() %>