diff --git a/_config.yml b/_config.yml index abdb834..7d614fc 100755 --- a/_config.yml +++ b/_config.yml @@ -20,8 +20,8 @@ open_graph: ######## Sidebar ######## # 左上角显示的 logo 区域,包含图标、大标题、副标题 logo: - avatar: '[config.avatar](/about/)' # you can set avatar link in _config.yml or '[https://xxx.png](/about/)' - title: '[config.title](/)' # you can set html tag like: '[](/)' + avatar: '[${config.avatar}](/about/)' # you can set avatar link in _config.yml or '[https://xxx.png](/about/)' + title: '[${config.title}](/)' # you can set html tag like: '[](/)' subtitle: '' # '文字1 | 文字2' (鼠标放上去会切换到文字2) # 侧边栏主功能导航菜单 @@ -40,41 +40,41 @@ menu: site_tree: # 主页配置 home: - sidebar: search, recent, timeline - # 博客配置 + sidebar: recent, timeline + # 博客列表配置 blog: base_dir: blog # 只影响自动生成的页面路径 menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id - sidebar: search_blog, recent, timeline # for categories/tags/archives + sidebar: recent, timeline # for categories/tags/archives nav_tabs: # 近期发布 分类 标签 专栏 归档 and ... # '朋友文章': /friends/rss/ # 博客文章配置 post: menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id - sidebar: search_blog, toc, related, ghrepo, ghissues # for pages using 'layout:post' + sidebar: toc, related, ghrepo, ghissues, recent # for pages using 'layout:post' # 博客专栏配置 topic: base_dir: topic # 只影响自动生成的页面路径 menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 topic 的页面默认使用这里配置的 menu_id - sidebar: search_blog, toc, related # for topic + sidebar: toc, related # for topic # wiki配置 wiki: base_dir: wiki # 只影响自动生成的页面路径 menu_id: wiki # 未在 front-matter 中指定 menu_id 时,layout 为 wiki 的页面默认使用这里配置的 menu_id - sidebar: search_docs, toc, ghissues, related # for wiki + sidebar: toc, ghissues, related, recent # for wiki # 作者信息配置 author: base_dir: author # 只影响自动生成的页面路径 menu_id: post - sidebar: search_blog, recent, timeline + sidebar: recent, timeline # 错误页配置 error_page: menu_id: post '404': '/404.html' - sidebar: search, recent, timeline + sidebar: recent, timeline # 其它自定义页面配置 layout: page page: - sidebar: toc, search + sidebar: toc, timeline @@ -448,7 +448,7 @@ style: border-radius: card: 12px block: 12px - bar: 6px + bar: 8px image: 6px color: # 动态颜色(会根据明暗主题重设明度值,只用关心色相和饱和度即可) @@ -485,6 +485,7 @@ default: project: https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2779789.png banner: https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/banner/books.jpg topic: https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/10433048.png + sidebar: https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.13/image/sidebar-bg1@small.jpg api_host: ghapi: https://api.github.com diff --git a/_data/widgets.yml b/_data/widgets.yml index 1c0cc5c..20448b9 100644 --- a/_data/widgets.yml +++ b/_data/widgets.yml @@ -2,21 +2,7 @@ # layout即组件布局,支持自定义的有: # - markdown: 渲染 md 文本 # -search: - layout: search - filter: auto # auto or 'path' - -search_blog: - layout: search - filter: /blog/ # auto or 'path' - placeholder: 文章搜索 - -search_docs: - layout: search - filter: /wiki/ # auto or 'path' - placeholder: 文档搜索 - ghrepo: layout: ghrepo related: @@ -33,7 +19,7 @@ ghissues: recent: layout: recent rss: # /atom.xml # npm i hexo-generator-feed - limit: 5 # Count of posts + limit: 10 # Count of posts # TOC (valid only in layout:post/wiki) toc: @@ -41,7 +27,7 @@ toc: list_number: false min_depth: 2 max_depth: 5 - fallback: recent # Use a backup widget when toc does not exist. + fallback: # recent # Use a backup widget when toc does not exist. collapse: false # true / false / auto # github user info diff --git a/layout/_partial/main/header/index.ejs b/layout/_partial/main/header/index.ejs index ee9e064..8ec1be6 100644 --- a/layout/_partial/main/header/index.ejs +++ b/layout/_partial/main/header/index.ejs @@ -1,3 +1,3 @@ <% if (page.header != 'auto' && page.header != false) { %> - <%- partial('../../sidebar/header', {where: 'main'}) %> + <%- partial('../../sidebar/logo', {logo: theme.logo, where: 'main'}) %> <% } %> diff --git a/layout/_partial/menubtn.ejs b/layout/_partial/menubtn.ejs index 8de06de..64a91a0 100644 --- a/layout/_partial/menubtn.ejs +++ b/layout/_partial/menubtn.ejs @@ -1,5 +1,5 @@ diff --git a/layout/_partial/sidebar/header.ejs b/layout/_partial/sidebar/header.ejs deleted file mode 100644 index cf8613a..0000000 --- a/layout/_partial/sidebar/header.ejs +++ /dev/null @@ -1,58 +0,0 @@ -<% -var proj; -if (page.layout === 'wiki' && page.wiki) { - proj = theme.wiki.tree[page.wiki]; -} -function layoutTitle(main, url, sub) { - var el = ''; - el += ''; - el += '
' + main + '
'; - if (sub) { - let arr = sub.split('|'); - if (arr.length > 1) { - el += '
' + arr.shift().trim() + '
'; - el += '
' + arr.join('|') + '
'; - } else { - el += '
' + sub + '
'; - } - } - el += '
'; - return el; -} - -function layoutDiv() { - var el = ''; - if (page.layout == 'wiki' && page.menu_id == 'wiki') { - return el; - } - el += '
'; - - el += '
'; - if (md_text(theme.logo.avatar)) { - el += ''; - if (theme.style.animated_avatar.animate) { - el += '
'; - } - el += ''; - el += '
'; - } - let main = md_text(theme.logo.title); - if (main) { - let url = md_link(theme.logo.title); - el += layoutTitle(main, url, theme.logo.subtitle); - } - el += '
'; - - if (where != 'main') { - el += partial('menu', {where: where}); - } - el += '
'; - return el; -} -%> - -<%- layoutDiv() %> diff --git a/layout/_partial/sidebar/index.ejs b/layout/_partial/sidebar/index.ejs index 013cae7..64bcd24 100755 --- a/layout/_partial/sidebar/index.ejs +++ b/layout/_partial/sidebar/index.ejs @@ -28,10 +28,11 @@ if (page.sidebar == null) { if (page.layout == 'wiki' && page.wiki && theme.wiki?.tree[page.wiki]?.sidebar) { sidebar = theme.wiki.tree[page.wiki].sidebar } - + page.sidebar = sidebar } + console.log('s', sidebar); // parse array string if (typeof page.sidebar == 'string') { page.sidebar = page.sidebar.replace(/ /g, '').split(','); @@ -59,31 +60,6 @@ function layoutWidgets() { proj = theme.wiki.tree[page.wiki]; } 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.menu[page.menu_id] && md_link(theme.menu[page.menu_id])) { - proj = { - path: md_link(theme.menu[page.menu_id]), - wiki: __(md_text(theme.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) => { let name = '' @@ -142,9 +118,62 @@ function layoutFooterDiv() { } } +function layoutLogo() { + var logo = theme.logo + if (page.logo) { + logo = page.logo + } else if (page.wiki && page.layout == 'wiki' && theme.wiki.tree[page.wiki]) { + const proj = theme.wiki.tree[page.wiki] + var l = proj.logo + if (l) { + logo = l + } else if (proj.name || proj.icon) { + logo = { + icon: proj.icon || theme.default.project, + title: `[${proj.name || proj.title}](${url_for(proj.homepage?.path || '')})`, + subtitle: proj.subtitle + } + } + } else if (page.topic && page.layout == 'topic' && theme.topic.tree[page.topic]) { + const topic = theme.topic.tree[page.topic] + var l = topic.logo + if (l) { + logo = l + } else if (topic.name || topic.icon) { + logo = { + icon: topic.icon || theme.default.topic, + title: `[${topic.name || topic.title}](${url_for(topic.homepage?.path || '')})`, + subtitle: topic.subtitle + } + } + } + return partial('logo', {logo: logo, where: 'sidebar'}) +} + +function layoutNavArea() { + var search = {} + if (page.search) { + search = page.search + } else if (page.wiki && page.layout == 'wiki' && theme.wiki.tree[page.wiki]) { + const proj = theme.wiki.tree[page.wiki] + if (proj.search) { + search = proj.search + } + } else if (page.topic && page.layout == 'topic' && theme.topic.tree[page.topic]) { + const topic = theme.topic.tree[page.topic] + if (topic.search) { + search = topic.search + } + } + var el = '' + el += `` + return el +} %> -<% if (page.header == undefined || page.header == 'left' || page.header == 'auto') { %> - <%- partial('header', {where: 'sidebar'}) %> -<% } %> +<%- layoutLogo() %> +<%- layoutNavArea() %> <%- layoutWidgets() %> <%- layoutFooterDiv() %> diff --git a/layout/_partial/sidebar/logo.ejs b/layout/_partial/sidebar/logo.ejs new file mode 100644 index 0000000..f72a7e5 --- /dev/null +++ b/layout/_partial/sidebar/logo.ejs @@ -0,0 +1,45 @@ +<% +// logo.icon, logo.title, logo.subtitle, logo.url +function layoutTitle(main, url, sub) { + var el = '' + el += `` + el += `
${main}
` + if (sub) { + const arr = sub.split('|') + if (arr.length > 1) { + el += `
${arr.shift().trim()}
` + el += `
${arr.join('|')}
` + } else { + el += `
${sub}
` + } + } + el += `
` + return el +} + +function layoutDiv() { + var el = '' + el += `
` + el += `
` + if (logo.icon) { + el += `
` + } else if (md_text(logo.avatar)) { + el += `` + if (theme.style.animated_avatar.animate) { + el += `
` + } + el += `` + el += `
` + } + const main = md_text(logo.title) + if (main) { + let url = md_link(logo.title) + el += layoutTitle(main, url, logo.subtitle) + } + el += `
` + el += '
' + return el +} +%> + +<%- layoutDiv() %> diff --git a/layout/_partial/sidebar/menu.ejs b/layout/_partial/sidebar/menu.ejs index 52fde0e..5827cde 100644 --- a/layout/_partial/sidebar/menu.ejs +++ b/layout/_partial/sidebar/menu.ejs @@ -1,26 +1,18 @@ <% function layoutDiv() { - var el = ''; - el += '` + return el } %> diff --git a/layout/_partial/sidebar/search.ejs b/layout/_partial/sidebar/search.ejs new file mode 100644 index 0000000..ce82bc4 --- /dev/null +++ b/layout/_partial/sidebar/search.ejs @@ -0,0 +1,42 @@ +<% +if (item.filter == null) { + item.filter = 'auto' +} +function layoutDiv() { + var el = '' + el += `
` + el += `
` + var filter = '' + if (item.filter == 'auto') { + if (page.layout == 'wiki') { + let matches = page.path.match(/(.*?)\/(.*?)\//i) + if (matches?.length > 0) { + filter = matches[0] + } + } + } else { + if (item.filter?.length > 0) { + filter = item.filter + } + } + el += `` + el += `` + el += `` + el += ` 0) { + if (!filter.startsWith('/')) { + filter = '/' + filter + } + el += ` data-filter="${filter}"` + el += ` placeholder="${item.placeholder || __('search.search_in', filter)}">` + } else { + el += ` placeholder="${item.placeholder || __('search.search')}">` + } + el += `
` + el += `
` + el += `
${__('search.no_results')}
` + el += `
` + return el +} +%> +<%- layoutDiv() %> diff --git a/layout/_partial/widgets/ghissues.ejs b/layout/_partial/widgets/ghissues.ejs index e01a2fd..5aa3eef 100644 --- a/layout/_partial/widgets/ghissues.ejs +++ b/layout/_partial/widgets/ghissues.ejs @@ -23,7 +23,7 @@ function layoutDiv() { } el += ''; if (item.title) { - el += '
'; + el += '
'; el += '' + item.title + ''; el += '
'; } diff --git a/layout/_partial/widgets/ghuser.ejs b/layout/_partial/widgets/ghuser.ejs index b8abff6..10112bb 100644 --- a/layout/_partial/widgets/ghuser.ejs +++ b/layout/_partial/widgets/ghuser.ejs @@ -45,10 +45,6 @@ function layoutDiv() { el += ''; el += 'Follow'; el += ''; - // menu - if (item.menu) { - el += partial('../sidebar/menu', {where: 'sidebar'}); - } el += '
'; el += '
'; return el; diff --git a/layout/_partial/widgets/markdown.ejs b/layout/_partial/widgets/markdown.ejs index 6241f89..802192e 100644 --- a/layout/_partial/widgets/markdown.ejs +++ b/layout/_partial/widgets/markdown.ejs @@ -4,7 +4,7 @@ function layoutDiv() { var el = ''; el += ''; if (item.title?.length > 0) { - el += '
'; + el += '
'; el += '' + item.title + ''; el += '
'; } diff --git a/layout/_partial/widgets/recent.ejs b/layout/_partial/widgets/recent.ejs index e5ed8d8..545c090 100644 --- a/layout/_partial/widgets/recent.ejs +++ b/layout/_partial/widgets/recent.ejs @@ -1,8 +1,8 @@ <% function layoutDiv() { - var el = ''; + var el = ''; // header - el += '
'; + el += '
'; el += '' + __("meta.recent_update") + ''; if (item.rss) { el += ''; @@ -25,11 +25,12 @@ function layoutDiv() { arr = site.posts.filter( p => p.title && p.title.length > 0) arr = arr.sort("updated", -1) } - el += '