From 2c20cb904060aa2a6866878574c53beb6453a9e2 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sat, 19 Nov 2022 16:48:44 +0800 Subject: [PATCH] [opt] wiki sidebar --- layout/_partial/head.ejs | 6 +-- layout/_partial/sidebar/header.ejs | 51 +++++++++++++++--- layout/_partial/sidebar/index.ejs | 46 ++++++++++++++++- layout/_partial/sidebar/logo.ejs | 69 ------------------------- layout/_partial/sidebar/widgets/toc.ejs | 6 ++- source/css/_layout/sidebar/sidebar.styl | 6 +-- 6 files changed, 98 insertions(+), 86 deletions(-) delete mode 100644 layout/_partial/sidebar/logo.ejs diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index 61ef8cb..1be6b21 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -13,16 +13,14 @@ function generate_title() { } } else { if (page.title) { - return page.title; + return page.title + ' - ' + config.title; } else if (page.category) { return __('btn.category') + __('symbol.colon') + page.category + ' - ' + config.title; } else if (page.tag) { return __('btn.tag') + __('symbol.colon') + page.tag + ' - ' + config.title; - } else { - return config.title; } } - return ''; + return config.title; } function generate_description() { if (theme.open_graph && theme.open_graph.enable) { diff --git a/layout/_partial/sidebar/header.ejs b/layout/_partial/sidebar/header.ejs index 6b51076..729d672 100644 --- a/layout/_partial/sidebar/header.ejs +++ b/layout/_partial/sidebar/header.ejs @@ -1,20 +1,55 @@ <% +var proj; +if (page.layout === 'wiki' && page.wiki) { + proj = theme.wiki.projects[page.wiki]; +} +function layoutTitle(main, url, sub) { + var el = ''; + el += ''; + el += '
' + main + '
'; + if (sub) { + let arr = sub.split('|'); + if (arr.length > 1) { + el += '
' + arr[0].trim() + '
'; + el += '
' + arr[1].trim() + '
'; + } else if (arr.length > 0) { + el += '
' + arr[0] + '
'; + } + } + el += '
'; + return el; +} + function layoutDiv() { var el = ''; + if (page.layout == 'wiki' && page.menu_id == 'wiki') { + return el; + } el += '
'; - el += partial('logo'); - if (where != 'main') { - if (page.layout === 'wiki' && page.wiki) { - if (page.menu_id !== 'wiki') { - el += partial('menu', {where: where}); - } - } else { - el += partial('menu', {where: where}); + + el += '
'; + if (md_text(theme.sidebar.logo.avatar)) { + el += ''; + if (theme.style.animated_avatar.animate) { + el += '
'; } + el += ''; + el += '
'; + } + let main = md_text(theme.sidebar.logo.title); + if (main) { + let url = md_link(theme.sidebar.logo.title); + let sub = config.subtitle; + el += layoutTitle(main, url, sub); + } + el += '
'; + + if (where != 'main') { + el += partial('menu', {where: where}); } el += '
'; return el; diff --git a/layout/_partial/sidebar/index.ejs b/layout/_partial/sidebar/index.ejs index c01377d..558d6e7 100755 --- a/layout/_partial/sidebar/index.ejs +++ b/layout/_partial/sidebar/index.ejs @@ -1,4 +1,8 @@ <% +var proj; +if (page.layout === 'wiki' && page.wiki) { + proj = theme.wiki.projects[page.wiki]; +} // 默认组件 if (page.sidebar == undefined) { if (page.layout == 'post' && page.content) { @@ -23,10 +27,50 @@ if (page.sidebar == undefined) { if (typeof page.sidebar == 'string') { page.sidebar = page.sidebar.replace(/ /g, '').split(','); } - +function layoutTitle(main, url, sub) { + var el = ''; + el += ''; + el += '
' + main + '
'; + if (sub) { + let arr = sub.split('|'); + if (arr.length > 1) { + el += '
' + arr[0].trim() + '
'; + el += '
' + arr[1].trim() + '
'; + } else if (arr.length > 0) { + el += '
' + arr[0] + '
'; + } + } + el += '
'; + return el; +} function layoutWidgets() { var el = ''; el += '
'; + if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') { + el += '
'; + // all products + el += ''; + el += ''; + el += __('btn.all_wiki'); + el += ''; + // this product + if (proj == undefined) { + // 如果没有项目名,则使用menu中显示的名字 + if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) { + proj = { + path: md_link(theme.sidebar.menu[page.menu_id]), + wiki: __(md_text(theme.sidebar.menu[page.menu_id])) + }; + } + } + if (proj != undefined) { + let main = proj.name || proj.title || page.wiki || page.title; + let url = proj.homepage.path; + let sub = proj.subtitle; + el += layoutTitle(main, url, sub); + } + el += '
'; + } if (page.sidebar) { page.sidebar.forEach((w, i) => { if (w in theme.data.widgets) { diff --git a/layout/_partial/sidebar/logo.ejs b/layout/_partial/sidebar/logo.ejs deleted file mode 100644 index 9c7781c..0000000 --- a/layout/_partial/sidebar/logo.ejs +++ /dev/null @@ -1,69 +0,0 @@ -<% -var proj; -if (page.layout === 'wiki' && page.wiki) { - proj = theme.wiki.projects[page.wiki]; -} -function layoutTitle(main, url, sub) { - var el = ''; - el += ''; - el += '
' + main + '
'; - if (sub) { - let arr = sub.split('|'); - if (arr.length > 1) { - el += '
' + arr[0].trim() + '
'; - el += '
' + arr[1].trim() + '
'; - } else if (arr.length > 0) { - el += '
' + arr[0] + '
'; - } - } - el += '
'; - return el; -} -function layoutDiv() { - var el = ''; - if (page.layout == 'wiki' && proj && proj.index != false) { - el += '
'; - // all products - el += ''; - el += ''; - el += __('btn.all_wiki'); - el += ''; - // this product - if (proj == undefined) { - // 如果没有项目名,则使用menu中显示的名字 - if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) { - proj = { - path: md_link(theme.sidebar.menu[page.menu_id]), - wiki: __(md_text(theme.sidebar.menu[page.menu_id])) - }; - } - } - if (proj != undefined) { - let main = proj.name || proj.title || page.wiki || page.title; - let url = proj.homepage.path; - let sub = proj.subtitle; - el += layoutTitle(main, url, sub); - } - } else { - el += '
'; - if (md_text(theme.sidebar.logo.avatar)) { - el += ''; - if (theme.style.animated_avatar.animate) { - el += '
'; - } - el += ''; - el += '
'; - } - let main = md_text(theme.sidebar.logo.title); - if (main) { - let url = md_link(theme.sidebar.logo.title); - let sub = config.subtitle; - el += layoutTitle(main, url, sub); - } - } - el += '
'; - return el; -} -%> - -<%- layoutDiv() %> diff --git a/layout/_partial/sidebar/widgets/toc.ejs b/layout/_partial/sidebar/widgets/toc.ejs index a0d9302..0877528 100644 --- a/layout/_partial/sidebar/widgets/toc.ejs +++ b/layout/_partial/sidebar/widgets/toc.ejs @@ -29,7 +29,11 @@ function layoutDocTree(pages) { } el += '
'; if (proj.pages.length > 1) { - el += ''; + let href = url_for(p.path); + if (i == 0) { + href += '#start' + } + el += ''; el += '' + (p.title || p.seo_title) + ''; el += ''; } diff --git a/source/css/_layout/sidebar/sidebar.styl b/source/css/_layout/sidebar/sidebar.styl index 0c3ec74..7449985 100644 --- a/source/css/_layout/sidebar/sidebar.styl +++ b/source/css/_layout/sidebar/sidebar.styl @@ -100,12 +100,12 @@ opacity: 1 !important -.logo-wrap.wiki - margin: 1rem 0 1.5rem 0 +.l_left .widgets .widget-wrap.logo-wrap.wiki + margin-bottom: 1.5rem flex-direction: column align-items: flex-start a.wiki-home - margin-bottom: 1rem + margin-bottom: 0.5rem color: var(--text-p1) svg margin-right: 2px