From 3b489d6146a886dafa1da82ae89b4f583ce93dbf Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sun, 4 Jul 2021 22:53:55 +0800 Subject: [PATCH] repo info widget --- _config.yml | 2 +- layout/_partial/sidebar/index.ejs | 45 +++++++------ layout/_partial/sidebar/widgets/repo_info.ejs | 64 +++++++++++++++++++ scripts/events/lib/config.js | 8 +-- source/css/_layout/sidebar/repo_info.styl | 18 ++++++ 5 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 layout/_partial/sidebar/widgets/repo_info.ejs create mode 100644 source/css/_layout/sidebar/repo_info.styl diff --git a/_config.yml b/_config.yml index caab23c..864994a 100755 --- a/_config.yml +++ b/_config.yml @@ -26,7 +26,7 @@ sidebar: # Sidebar widgets widgets: # default layout in home/wiki/categories/tags/archives pages - default: # [welcome, recent] + default_layout: [welcome, recent] # Recent update recent: layout: recent diff --git a/layout/_partial/sidebar/index.ejs b/layout/_partial/sidebar/index.ejs index e37dd74..30d9292 100755 --- a/layout/_partial/sidebar/index.ejs +++ b/layout/_partial/sidebar/index.ejs @@ -2,13 +2,27 @@ // 默认组件 if (page.sidebar == undefined) { if (page.layout == 'post' && page.content) { - page.sidebar = ['toc']; + page.sidebar = ['toc', 'repo_info']; } else if (page.layout == 'wiki' && page.content) { - page.sidebar = ['toc', 'wiki_more']; + page.sidebar = ['toc', 'repo_info', 'wiki_more']; } else { - page.sidebar = theme.sidebar.widgets.default; + page.sidebar = theme.sidebar.widgets.default_layout; } } +function layoutWidgets() { + var el = ''; + el += '
'; + if (page.sidebar) { + page.sidebar.forEach((w, i) => { + if (w in theme.sidebar.widgets) { + let widget = theme.sidebar.widgets[w]; + el += partial('widgets/' + widget.layout, {item: widget}); + } + }); + } + el += '
'; + return el; +} function layoutFooterDiv() { if (theme.footer.social && theme.footer.social.length > 0) { var el = '