[opt] article top area & sidebar

This commit is contained in:
xaoxuu 2024-01-20 01:51:09 +08:00
parent 873279b45c
commit 46e72d1eb0
17 changed files with 218 additions and 198 deletions

View File

@ -59,28 +59,38 @@ menubar:
######## Main ########
# 站点主结构树
site_tree:
# -- 列表类页面 -- #
# 主页配置
home:
sidebar: recent, timeline
# 博客列表配置
blog:
sidebar: welcome, recent, timeline
# 博客列表配置
index_blog:
base_dir: blog # 只影响自动生成的页面路径
menu_id: post # 未在 front-matter 中指定 menu_id 时layout 为 post 的页面默认使用这里配置的 menu_id
sidebar: recent, timeline # for categories/tags/archives
sidebar: welcome, recent, timeline # for categories/tags/archives
nav_tabs: # 近期发布 分类 标签 专栏 归档 and ...
# '朋友文章': /friends/rss/
# 博客文章配置
# 博客专栏列表页配置
index_topic:
base_dir: topic # 只影响自动生成的页面路径
menu_id: post # 未在 front-matter 中指定 menu_id 时layout 为 topic 的页面默认使用这里配置的 menu_id
# 文档列表页配置
index_wiki:
base_dir: wiki # 只影响自动生成的页面路径
menu_id: wiki # 未在 front-matter 中指定 menu_id 时layout 为 wiki 的页面默认使用这里配置的 menu_id
sidebar: toc, ghissues, related, recent # for wiki
nav_tabs:
# 'more': https://github.com/xaoxuu
# -- 内容类页面 -- #
# 博客文章内页配置
post:
menu_id: post # 未在 front-matter 中指定 menu_id 时layout 为 post 的页面默认使用这里配置的 menu_id
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: toc, related # for topic
# wiki配置
menu_id: post
# 文档内页配置
wiki:
base_dir: wiki # 只影响自动生成的页面路径
menu_id: wiki # 未在 front-matter 中指定 menu_id 时layout 为 wiki 的页面默认使用这里配置的 menu_id
sidebar: toc, ghissues, related, recent # for wiki
# 作者信息配置
@ -95,7 +105,7 @@ site_tree:
sidebar: recent, timeline
# 其它自定义页面配置 layout: page
page:
sidebar: toc, timeline
sidebar: toc, recent, timeline

View File

@ -1,7 +1,7 @@
btn:
home: 主页
blog: 文章
wiki: 项目
wiki: 文档
topic: 专栏
recent_publish: 近期发布
all_wiki: 所有项目

View File

@ -1,7 +1,7 @@
btn:
home: 首頁
blog: 網誌
wiki: Wiki
wiki: 文檔
topic: 專欄
recent_publish: 近期發布
all_wiki: 所有 Wiki

View File

@ -0,0 +1,35 @@
<%
function layoutDiv() {
if (page.breadcrumb === false) {
return ''
}
var el = ''
// 1.main
el += `<div class="bread-nav fs12">`
// 2.left
el += `<div class="left">`
// 3.left.top: 面包屑导航
el += `<div id="breadcrumb">`
// 首页
el += `<a class="cap breadcrumb" href="${url_for(config.root)}">${__("btn.home")}</a>`
if (theme.wiki.tree[page.wiki]) {
el += partial('breadcrumb/wiki')
} else if (page.layout == 'post') {
el += partial('breadcrumb/blog')
} else {
el += partial('breadcrumb/page')
}
// end 3.left.top
el += `</div>`
// 3.left.bottom
el += partial('dateinfo')
// end 2.left
el += `</div>`
// 2.right
el += partial('ghinfo')
// end 1.main
el += `</div>`
return el
}
%>
<%- layoutDiv() %>

View File

@ -1,155 +0,0 @@
<%
function layoutDiv() {
var el = '';
if (page.breadcrumb === false) {
return el;
}
var home_title = __("btn.home");
if (page.layout === "post") {
var firstCat = "";
if (page.categories && page.categories.length > 0) {
firstCat = page.categories.data[0].name;
}
el += '<div class="bread-nav fs12">';
el += '<div class="left">';
el += '<div id="breadcrumb">';
el += '<a class="cap breadcrumb" href="' + url_for(config.root) + '">' + home_title + '</a>';
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="' + url_for(config.index_generator.path) + '">' + __("btn.blog") + '</a>';
if (page.layout == "post" && page.categories && page.categories.length > 0) {
el += '<span class="sep"></span>';
el += list_categories(page.categories, {
class: "cap breadcrumb",
show_count: false,
separator: ' <span class="sep"></span> ',
style: "none"
});
}
el += '</div>';
// 作者
var author = null
if (theme.authors) {
if (page.author?.length > 0 && theme.authors[page.author] != null) {
author = theme.authors[page.author]
} else {
author = theme.default_author
}
}
el += '<div id="post-meta">';
if (author) {
let link = `<a href="${url_for(author.path)}">${author.name}</a>`
el += `<span class="author">${__("meta.created_author", link)}</span>`
} else {
el += `<span class="author">${__("meta.created")}</span>`
}
// 发布日期
el += `
<span class="created"><time datetime="${date_xml(page.date)}">${date(page.date, config.date_format)}</time></span>
`;
// 更新日期
el += `
<span class="updated">${__("symbol.comma") + __("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`;
el += '</div>';
el += '</div>';
el += '</div>';
} else if (page.topic?.length > 0) {
el += '<div class="bread-nav fs12">';
el += '<div class="left">';
el += '<div id="breadcrumb">';
var nodes = [];
// home
el += '<a class="cap breadcrumb" id="home" href="' + url_for(config.root) + '">' + home_title + '</a>';
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
let url = url_for(theme.site_tree.topic.base_dir);
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.topic") + '</a>';
// 专栏名
let topicObject = theme.topic.tree[page.topic];
if (topicObject != null) {
let url_proj = url_for(topicObject.homepage?.path);
if (nodes.includes(url_proj) === false) {
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" id="proj" href="' + url_proj + '">' + (topicObject.name || topicObject.title) + '</a>';
}
}
el += '</div>';
// 更新日期
el += '<div id="post-meta">';
el += `
<span>${__("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`;
el += '</div>';
el += '</div>';
el += '</div>';
} else if (page.layout === "wiki" && page.wiki?.length > 0) {
el += '<div class="bread-nav fs12">';
el += '<div class="left">';
el += '<div id="breadcrumb">';
var nodes = [];
// home
el += '<a class="cap breadcrumb" id="home" href="' + url_for(config.root) + '">' + home_title + '</a>';
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
let url = url_for(theme.site_tree.wiki.base_dir);
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.wiki") + '</a>';
// 项目名
const proj = theme.wiki.tree[page.wiki]
if (proj != null) {
let url_proj = url_for(proj.homepage?.path);
if (nodes.includes(url_proj) === false) {
el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" id="proj" href="' + url_proj + '">' + (proj.name || proj.title) + '</a>';
}
}
el += '</div>';
// 更新日期
el += '<div id="post-meta">';
el += `
<span>${__("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`;
el += '</div>';
el += '</div>';
const repo = page.repo || proj?.repo
if (repo) {
el += `
<div class="right ghrepo stellar-ghinfo-api" api="${theme.api_host.ghapi}/repos/${repo}">
<a class="repo-link bold" href="https://github.com/${repo}">
${icon('github:repo')}
<span type="text">${repo}</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/stargazers">
${icon('github:star')}
<span type="text" id="stargazers_count">0</span><span>stars</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/forks">
${icon('github:fork')}
<span type="text" id="forks_count">0</span><span>forks</span>
</a>
</div>
`;
}
el += '</div>';
} else if (page.title) {
el += `
<div class="bread-nav fs12">
<div class="left">
<div id="breadcrumb">
<a class="cap breadcrumb" href="${url_for(config.root)}">${home_title}</a>
<span class="sep"></span>
<a class="cap breadcrumb" href="${url_for(page.path)}">${page.title}</a>
</div>
</div>
</div>
`;
}
return el;
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,34 @@
<%
function layoutDiv() {
const topicObject = theme.topic.tree[page.topic]
var el = ''
if (topicObject) { // 专栏文章
// 专栏列表页
const topicIndexPageURL = url_for(theme.site_tree.index_topic.base_dir)
el += `<span class="sep"></span>`
el += `<a class="cap breadcrumb" id="menu" href="${topicIndexPageURL}">${__("btn.topic")}</a>`
// 专栏项目名
const topicHomePageURL = url_for(topicObject.homepage?.path);
if (topicHomePageURL != topicIndexPageURL) {
el += `<span class="sep"></span>`
el += `<a class="cap breadcrumb" id="proj" href="${topicHomePageURL}">${topicObject.name || topicObject.title}</a>`
}
} else { // 普通文章
// 文章列表页
el += `<span class="sep"></span>`
el += `<a class="cap breadcrumb" href="${url_for(config.index_generator.path)}">${__("btn.blog")}</a>`
// 分类列表页
if (page.categories?.length > 0) {
el += `<span class="sep"></span>`
el += list_categories(page.categories, {
class: "cap breadcrumb",
show_count: false,
separator: ' <span class="sep"></span> ',
style: "none"
})
}
}
return el
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,10 @@
<%
function layoutDiv() {
// 普通页面就显示当前页面
return `
<span class="sep"></span>
<a class="cap breadcrumb" href="${url_for(page.path)}">${page.title}</a>
`
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,20 @@
<%
function layoutDiv() {
const wikiObject = theme.wiki.tree[page.wiki]
var el = ''
// 文档列表页
el += `<span class="sep"></span>`
const wikiIndexPageURL = url_for(theme.site_tree.index_wiki.base_dir)
el += `<a class="cap breadcrumb" id="menu" href="${wikiIndexPageURL}">${__("btn.wiki")}</a>`
if (wikiObject) {
// 文档项目名
const wikiHomePageURL = url_for(wikiObject.homepage?.path);
if (wikiHomePageURL != wikiIndexPageURL) {
el += `<span class="sep"></span>`
el += `<a class="cap breadcrumb" id="proj" href="${wikiHomePageURL}">${wikiObject.name || wikiObject.title}</a>`
}
}
return el
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,32 @@
<%
function layoutDiv() {
// 作者
const author = theme.authors ? (theme.authors[page.author] || theme.default_author) : null
var el = ''
el += `<div id="post-meta">`
if (page.wiki) {
el += `<span class="author">${__("meta.updated") + __("symbol.colon")}</span>`
el += `<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time>`
el += `</span>`
} else {
if (author) {
const link = `<a href="${url_for(author.path)}">${author.name}</a>`
el += `<span class="author">${__("meta.created_author", link) + __("symbol.colon")}</span>`
} else {
el += `<span class="author">${__("meta.created") + __("symbol.colon")}</span>`
}
// 发布日期
el += `<span class="created">`
el += `<time datetime="${date_xml(page.date)}">${date(page.date, config.date_format)}</time>`
el += `</span>`
// 更新日期
el += `<span class="updated">`
el += `${__("symbol.comma") + __("meta.updated") + __("symbol.colon")}`
el += `<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time>`
el += `</span>`
}
el += `</div>`
return el
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,25 @@
<%
function layoutDiv() {
const repo = page.repo || theme.wiki.tree[page.wiki]?.repo
if (repo == null) {
return ''
}
return `
<div class="right ghrepo stellar-ghinfo-api" api="${theme.api_host.ghapi}/repos/${repo}">
<a class="repo-link bold" href="https://github.com/${repo}">
${icon('github:repo')}
<span type="text">${repo}</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/stargazers">
${icon('github:star')}
<span type="text" id="stargazers_count">0</span><span>stars</span>
</a>
<a class="repo-link" href="https://github.com/${repo}/forks">
${icon('github:fork')}
<span type="text" id="forks_count">0</span><span>forks</span>
</a>
</div>
`
}
%>
<%- layoutDiv() %>

View File

@ -31,9 +31,9 @@ function layoutDiv() {
if (theme.topic?.publish_list?.length > 0) {
if (page.layout == 'index_topic') {
el += '<a class="active" href="' + url_for(theme.site_tree.topic.base_dir) + '">' + __("btn.topic") + '</a>';
el += '<a class="active" href="' + url_for(theme.site_tree.index_topic.base_dir) + '">' + __("btn.topic") + '</a>';
} else {
el += '<a href="' + url_for(theme.site_tree.topic.base_dir) + '">' + __("btn.topic") + '</a>';
el += '<a href="' + url_for(theme.site_tree.index_topic.base_dir) + '">' + __("btn.topic") + '</a>';
}
}
@ -45,7 +45,7 @@ function layoutDiv() {
}
}
const { nav_tabs } = theme.site_tree.blog
const { nav_tabs } = theme.site_tree.index_blog
if (nav_tabs) {
for (let key of Object.keys(nav_tabs)) {
// 当 page 的末尾为 index.html 或者处于该 page 的某个子页面时也应该匹配

View File

@ -8,7 +8,7 @@ function layoutDiv() {
if (page.filter === false) {
el += ' class="active"';
}
el += ' href="' + url_for(theme.site_tree.wiki.base_dir) + '">' + __("btn.all_wiki") + '</a>';
el += ' href="' + url_for(theme.site_tree.index_wiki.base_dir) + '">' + __("btn.all_wiki") + '</a>';
el += '</a>';
// 项目分类
const { shelf, all_tags } = theme.wiki;
@ -25,7 +25,7 @@ function layoutDiv() {
}
}
const { nav_tabs } = theme.site_tree.wiki
const { nav_tabs } = theme.site_tree.index_wiki
if (nav_tabs) {
for (let key of Object.keys(nav_tabs)) {
// 当 page 的末尾为 index.html 或者处于该 page 的某个子页面时也应该匹配

View File

@ -9,13 +9,16 @@ if (page.sidebar == null) {
if (is_home()) {
sidebar = site_tree.home.sidebar
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
sidebar = site_tree.blog.sidebar
sidebar = site_tree.index_blog.sidebar
} else if (page.layout === 'index_topic') {
// 专栏列表页等同于博客列表页
sidebar = site_tree.blog.sidebar
sidebar = site_tree.index_blog.sidebar
} else if (page.topic?.length > 0) {
sidebar = site_tree.topic.sidebar
} else if (page.layout === 'index_wiki' || page.wiki) {
// 专栏文章内页等同于普通文章内页
sidebar = site_tree.post.sidebar
} else if (page.layout === 'index_wiki') {
sidebar = site_tree.index_wiki.sidebar
} else if (page.wiki?.length > 0) {
sidebar = site_tree.wiki.sidebar
} else if (page.layout === '404') {
sidebar = site_tree.error_page.sidebar

View File

@ -7,10 +7,12 @@ const isUsingTianliGPT = theme.plugins.tianli_gpt.enable && ['all', page.layout]
// 默认的 menu_id
if (page.menu_id == null) {
if (page.wiki) {
page.menu_id = 'wiki'
if (page.wiki?.length > 0) {
page.menu_id = theme.site_tree.wiki.menu_id
} else if (page.topic?.length > 0) {
page.menu_id = theme.site_tree.topic.menu_id
} else {
page.menu_id = 'post'
page.menu_id = theme.site_tree.post.menu_id
}
}
// 默认的 title
@ -46,7 +48,7 @@ function layoutDiv() {
el += partial('_partial/main/navbar/nav_tabs_blog')
}
if (page.h1 || page.title || (page.content && page.content.length > 0)) {
el += partial('_partial/main/navbar/breadcrumb')
el += partial('_partial/main/navbar/article_top_area')
}
el += `<article class="${articleClass()}">`
el += layoutTitle()

View File

@ -34,11 +34,15 @@ function getWikiObject(ctx) {
if (obj.sort == null) {
obj.sort = 0
}
if (obj.path?.startsWith('/')) {
obj.path = obj.path.substring(1)
if (obj.base_dir) {
if (obj.base_dir.startsWith('/')) {
obj.base_dir = obj.base_dir.substring(1)
}
if (obj.path?.endsWith('/') == false) {
obj.path = obj.path + '/'
if (obj.base_dir.length > 1 && obj.base_dir.endsWith('/') == false) {
obj.base_dir = obj.base_dir + '/'
}
} else {
obj.base_dir = ''
}
list.push(obj)
}
@ -104,7 +108,7 @@ module.exports = ctx => {
for (let id of Object.keys(item.toc)) {
const sec = item.toc[id]
for (let key of sec) {
let hs = sub_pages.filter(p => p.path_key == item.path + key)
let hs = sub_pages.filter(p => p.path_key == item.base_dir + key)
if (hs.length > 0) {
item.homepage = hs[0]
break
@ -127,21 +131,21 @@ module.exports = ctx => {
for (let title of Object.keys(item.toc)) {
var sec = { title: title, pages: []}
for (let key of item.toc[title]) {
sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.path + key))
others = others.filter(p => p.path_key != item.path + key)
sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.base_dir + key))
others = others.filter(p => p.path_key != item.base_dir + key)
}
sections.push(sec)
}
if (others.length > 0 && others.filter(p => p.title?.length > 0).length > 0) {
sections.push({
title: '...',
pages: others.sort((p1, p2) => p1.path - p2.path)
pages: others.sort((p1, p2) => p1.title - p2.title)
})
}
} else {
// 自动设置顺序
sections.push({
pages: sub_pages.sort((p1, p2) => p1.path - p2.path)
pages: sub_pages.sort((p1, p2) => p1.title - p2.title)
})
}
@ -176,7 +180,7 @@ module.exports = ctx => {
}
all_tags[tag_name] = {
name: tag_name,
path: (ctx.theme.config.site_tree.wiki.base_dir) + '/tags/' + tag_name + '/index.html',
path: (ctx.theme.config.site_tree.index_wiki.base_dir) + '/tags/' + tag_name + '/index.html',
items: items
}
})

View File

@ -10,11 +10,11 @@ hexo.extend.generator.register('index_topic', function (locals) {
}
var ret = []
ret.push({
path: site_tree.topic.base_dir + '/index.html',
path: site_tree.index_topic.base_dir + '/index.html',
layout: ['index_topic'],
data: {
layout: 'index_topic',
menu_id: site_tree.topic.menu_id
menu_id: site_tree.index_topic.menu_id
}
})
return ret

View File

@ -10,11 +10,11 @@ hexo.extend.generator.register('wiki', function (locals) {
}
var ret = []
ret.push({
path: site_tree.wiki.base_dir + '/index.html',
path: site_tree.index_wiki.base_dir + '/index.html',
layout: ['index_wiki'],
data: {
layout: 'index_wiki',
menu_id: site_tree.wiki.menu_id,
menu_id: site_tree.index_wiki.menu_id,
filter: false
}
})
@ -26,7 +26,7 @@ hexo.extend.generator.register('wiki', function (locals) {
layout: ['index_wiki'],
data: {
layout: 'index_wiki',
menu_id: site_tree.wiki.menu_id,
menu_id: site_tree.index_wiki.menu_id,
filter: true,
tagName: tag.name,
title: tag.name