% 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() { if (page.rightbar == null || page.rightbar.length == 0) { return '' } var el = '' 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}) } }); } if (el.trim().length > 0) { return `
` } else { return '' } } %> <%- layoutWidgets() %>