diff --git a/_config.yml b/_config.yml index 4f3e53c..e2a2e31 100755 --- a/_config.yml +++ b/_config.yml @@ -62,12 +62,14 @@ site_tree: # -- 列表类页面 -- # # 主页配置 home: - leftbar: welcome, recent, timeline + leftbar: welcome, recent + rightbar: timeline # 博客列表页配置 index_blog: base_dir: blog # 只影响自动生成的页面路径 menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id - leftbar: welcome, recent, timeline # for categories/tags/archives + leftbar: welcome, recent # for categories/tags/archives + rightbar: timeline nav_tabs: # 近期发布 分类 标签 专栏 归档 and ... # '朋友文章': /friends/rss/ # 博客专栏列表页配置 @@ -78,34 +80,40 @@ site_tree: index_wiki: base_dir: wiki # 只影响自动生成的页面路径 menu_id: wiki # 未在 front-matter 中指定 menu_id 时,layout 为 wiki 的页面默认使用这里配置的 menu_id - leftbar: toc, ghissues, related, recent # for wiki + leftbar: ghissues, related, recent # for wiki + rightbar: timeline nav_tabs: # 'more': https://github.com/xaoxuu # -- 内容类页面 -- # # 博客文章内页配置 post: menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id - leftbar: toc, related, ghrepo, ghissues, recent # for pages using 'layout:post' + leftbar: related, ghrepo, ghissues, recent # for pages using 'layout:post' + rightbar: toc # 博客专栏文章内页配置 topic: menu_id: post # 文档内页配置 wiki: menu_id: wiki # 未在 front-matter 中指定 menu_id 时,layout 为 wiki 的页面默认使用这里配置的 menu_id - leftbar: toc, ghissues, related, recent # for wiki + leftbar: tree, ghissues, related, recent # for wiki + rightbar: toc # 作者信息配置 author: base_dir: author # 只影响自动生成的页面路径 menu_id: post leftbar: recent, timeline + rightbar: # 错误页配置 error_page: menu_id: post '404': '/404.html' leftbar: recent, timeline + rightbar: # 其它自定义页面配置 layout: page page: - leftbar: toc, recent, timeline + leftbar: recent + rightbar: toc, timeline diff --git a/_data/widgets.yml b/_data/widgets.yml index 20448b9..934117c 100644 --- a/_data/widgets.yml +++ b/_data/widgets.yml @@ -21,13 +21,15 @@ recent: rss: # /atom.xml # npm i hexo-generator-feed limit: 10 # Count of posts -# TOC (valid only in layout:post/wiki) +tree: + layout: tree + +# TOC (valid only in rightbar) toc: layout: toc - list_number: false - min_depth: 2 - max_depth: 5 - fallback: # recent # Use a backup widget when toc does not exist. + list_number: true + min_depth: 1 + max_depth: 6 collapse: false # true / false / auto # github user info diff --git a/layout/_partial/menubtn.ejs b/layout/_partial/menubtn.ejs index fc71874..e5c393c 100644 --- a/layout/_partial/menubtn.ejs +++ b/layout/_partial/menubtn.ejs @@ -1,5 +1,5 @@
diff --git a/layout/_partial/sidebar/index.ejs b/layout/_partial/sidebar/index_leftbar.ejs similarity index 99% rename from layout/_partial/sidebar/index.ejs rename to layout/_partial/sidebar/index_leftbar.ejs index 56ca751..d40142d 100755 --- a/layout/_partial/sidebar/index.ejs +++ b/layout/_partial/sidebar/index_leftbar.ejs @@ -47,6 +47,8 @@ if (page.leftbar == null) { if (typeof page.leftbar == 'string') { page.leftbar = page.leftbar.replace(/ /g, '').split(','); } + + function layoutTitle(main, url, sub) { var el = ''; el += ''; diff --git a/layout/_partial/sidebar/index_rightbar.ejs b/layout/_partial/sidebar/index_rightbar.ejs new file mode 100644 index 0000000..b94436e --- /dev/null +++ b/layout/_partial/sidebar/index_rightbar.ejs @@ -0,0 +1,79 @@ +<% + +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 += ' '; + return el; +} + +%> +<%- layoutWidgets() %> \ No newline at end of file diff --git a/layout/_partial/widgets/toc.ejs b/layout/_partial/widgets/toc.ejs index b72068a..5914a23 100644 --- a/layout/_partial/widgets/toc.ejs +++ b/layout/_partial/widgets/toc.ejs @@ -1,16 +1,13 @@ <% -const proj = theme.wiki.tree[page.wiki] -var hasTOC = true + function layoutTocBody() { if (toc(page.content).length > 0) { - hasTOC = true return toc(page.content, { list_number: item.list_number, min_depth: item.min_depth, max_depth: item.max_depth - }); + }) } - hasTOC = false return '' } @@ -22,94 +19,18 @@ function layoutTocHeader(title) { return el } -function layoutDocTree(pages) { - var el = '' - for (let p of pages) { - if (p.title == null || p.title.length == 0) { - continue - } - let isActive = '' - if (p.path === page.path) { - isActive += ' active' - } - el += `