[opt] refactoring

This commit is contained in:
xaoxuu 2024-01-14 16:42:20 +08:00
parent 3c115b66a7
commit 28f4beee04
28 changed files with 264 additions and 299 deletions

View File

@ -16,48 +16,58 @@ open_graph:
enable: true
twitter_id: # for open_graph meta
# 只影响生成的页面路径,不影响配置文件命名规则
base_dir:
wiki: wiki
topic: topic
author: author
######## head tags ########
# 站点主结构树
root:
# 主页配置
home:
sidebar: search, 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
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'
# 博客专栏配置
topic:
base_dir: topic # 只影响自动生成的页面路径
menu_id: post # 未在 front-matter 中指定 menu_id 时layout 为 topic 的页面默认使用这里配置的 menu_id
sidebar: search_blog, toc, related # for topic
# wiki配置
wiki:
base_dir: wiki # 只影响自动生成的页面路径
menu_id: wiki # 未在 front-matter 中指定 menu_id 时layout 为 wiki 的页面默认使用这里配置的 menu_id
sidebar: search_docs, ghissues, related, recent, timeline # for wiki
# 作者信息配置
author:
base_dir: author # 只影响自动生成的页面路径
menu_id: post
sidebar: search_blog, recent, timeline
# 错误页配置
error_page:
menu_id: post
'404': '/404.html'
sidebar: search, recent, timeline
# 其它自定义页面配置 layout: page
page:
sidebar: toc, search
######## Sidebar ########
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: '[<img no-lazy height="32px" src="xxx"/>](/)'
menu:
# post: '[btn.blog](/)'
# wiki: '[btn.wiki](/wiki/)'
# friends: '[友链](/friends/)'
# about: '[关于](/about/)'
# Sidebar widgets
widgets:
#### 自动生成的页面 ####
# 主页
home: search, recent, timeline # for home
# 博客索引页
blog_index: search_blog, recent, timeline # for categories/tags/archives
# 文档索引页
wiki_index: search_docs, recent, timeline # for wiki
# 专栏索引页
index_topic: search_blog, recent, timeline # for topic
# 其它404
others: search, recent, timeline # for 404 and ...
#### 手动创建的页面 ####
# 文章内页
post: search_blog, toc, related, ghrepo, ghissues # for pages using 'layout:post'
# 专栏内页
topic: search_blog, toc, related # for pages using 'layout:wiki'
# 文档内页
wiki: search_blog, toc, ghissues, related # for pages using 'layout:wiki'
# 其它 layout:page 的页面
page: toc, search # for custom pages using 'layout:page'
subtitle: # 文字1 | 文字2(鼠标放上去会切换到文字2)
######## Index ########
post-index: # 近期发布 分类 标签 归档 and ...
# '朋友文章': /friends/rss/
menu:
# post: '[btn.blog](/)'
# wiki: '[btn.wiki](/wiki/)'
# friends: '[友链](/friends/)'
# about: '[关于](/about/)'
######## Main ########

View File

@ -1,6 +1,4 @@
<%
page.menu_id = '404';
page.layout = '404';
page.comment_title = '';
page.header = 'auto';
page.robots = 'none';

View File

@ -4,25 +4,9 @@ function layoutDiv() {
var title = __('meta.read_next')
title_prev = __('meta.newer')
title_next = __('meta.older')
if (page.layout === 'post') {
if (page.layout === 'post' || page.layout === 'topic') {
prev = page.prev
next = page.next
} else if (page.layout === 'topic' && page.topic?.length > 0) {
const topicObject = theme.topic.tree[page.topic]
if (topicObject) {
const current_page_date = topicObject.pages.filter(p => p.path == page.path)[0].date
for (let p of topicObject.pages) {
if (p.date > current_page_date) {
if (prev == undefined || p.date < prev.date) {
prev = p
}
} else if (p.date < current_page_date) {
if (next == undefined || p.date > next.date) {
next = p
}
}
}
}
} else if (page.layout === 'wiki' && page.wiki?.length > 0) {
var title_prev = __('meta.prev');
var title_next = __('meta.next');

View File

@ -73,7 +73,7 @@ function layoutDiv() {
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
let url = url_for(theme.base_dir.topic);
let url = url_for(theme.root.topic.base_dir);
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.topic") + '</a>';
// 专栏名
@ -104,12 +104,12 @@ function layoutDiv() {
nodes.push('/');
// menu_id
el += '<span class="sep"></span>';
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
let url = url_for(md_link(theme.sidebar.menu[page.menu_id]));
if (page.menu_id && theme.menu[page.menu_id] && md_link(theme.menu[page.menu_id])) {
let url = url_for(md_link(theme.menu[page.menu_id]));
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __(md_text(theme.sidebar.menu[page.menu_id])) + '</a>';
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __(md_text(theme.menu[page.menu_id])) + '</a>';
} else {
let url = url_for(config.wiki_dir || "/wiki/");
let url = url_for(theme.root.wiki.base_dir);
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.wiki") + '</a>';
}

View File

@ -29,6 +29,14 @@ function layoutDiv() {
}
}
if (theme.topic?.publish_list?.length > 0) {
if (page.layout == 'index_topic') {
el += '<a class="active" href="' + url_for(theme.root.topic.base_dir) + '">' + __("btn.topic") + '</a>';
} else {
el += '<a href="' + url_for(theme.root.topic.base_dir) + '">' + __("btn.topic") + '</a>';
}
}
if (site.posts && site.posts.length > 0) {
if (is_archive()) {
el += '<a class="active" href="' + url_for(config.archive_dir) + '">' + __("btn.archives") + '</a>';
@ -36,23 +44,16 @@ function layoutDiv() {
el += '<a href="' + url_for(config.archive_dir) + '">' + __("btn.archives") + '</a>';
}
}
if (theme.topic?.publish_list?.length > 0) {
if (page.layout == 'index_topic') {
el += '<a class="active" href="' + url_for(theme.base_dir.topic) + '">' + __("btn.topic") + '</a>';
} else {
el += '<a href="' + url_for(theme.base_dir.topic) + '">' + __("btn.topic") + '</a>';
}
}
if (theme['post-index']) {
const obj = theme['post-index'];
for (let key of Object.keys(obj)) {
const { nav_tabs } = theme.root.blog
if (nav_tabs) {
for (let key of Object.keys(nav_tabs)) {
// 当 page 的末尾为 index.html 或者处于该 page 的某个子页面时也应该匹配
// if (full_url_for(page.path) == full_url_for(obj[key])) {
if (full_url_for(page.path).startsWith(full_url_for(obj[key]))){
el += '<a class="active" href="' + url_for(obj[key]) + '">' + key + '</a>';
// if (full_url_for(page.path) == full_url_for(nav_tabs[key])) {
if (full_url_for(page.path).startsWith(full_url_for(nav_tabs[key]))){
el += '<a class="active" href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
} else {
el += '<a href="' + url_for(obj[key]) + '">' + key + '</a>';
el += '<a href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
}
}
}

View File

@ -8,7 +8,7 @@ function layoutDiv() {
if (page.filter === false) {
el += ' class="active"';
}
el += ' href="' + url_for(config.wiki_dir || "/wiki/") + '">' + __("btn.all_wiki") + '</a>';
el += ' href="' + url_for(theme.root.wiki.base_dir) + '">' + __("btn.all_wiki") + '</a>';
el += '</a>';
// 项目分类
const { shelf, all_tags } = theme.wiki;
@ -24,6 +24,20 @@ function layoutDiv() {
el += '</a>';
}
}
const { nav_tabs } = theme.root.wiki
if (nav_tabs) {
for (let key of Object.keys(nav_tabs)) {
// 当 page 的末尾为 index.html 或者处于该 page 的某个子页面时也应该匹配
// if (full_url_for(page.path) == full_url_for(nav_tabs[key])) {
if (full_url_for(page.path).startsWith(full_url_for(nav_tabs[key]))){
el += '<a class="active" href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
} else {
el += '<a href="' + url_for(nav_tabs[key]) + '">' + key + '</a>';
}
}
}
el += '</nav>';
el += '</div>';
return el;

View File

@ -32,19 +32,18 @@ function layoutDiv() {
el += '">';
el += '<div class="logo-wrap">';
if (md_text(theme.sidebar.logo.avatar)) {
el += '<a class="avatar" href="' + url_for(md_link(theme.sidebar.logo.avatar) || "/") + '">';
if (md_text(theme.logo.avatar)) {
el += '<a class="avatar" href="' + url_for(md_link(theme.logo.avatar) || "/") + '">';
if (theme.style.animated_avatar.animate) {
el += '<div class="bg" style="opacity:0;background-image:url(' + theme.style.animated_avatar.background + ');"></div>';
}
el += '<img no-lazy class="avatar" src="' + md_text(theme.sidebar.logo.avatar) + '">';
el += '<img no-lazy class="avatar" src="' + md_text(theme.logo.avatar) + '">';
el += '</a>';
}
let main = md_text(theme.sidebar.logo.title);
let main = md_text(theme.logo.title);
if (main) {
let url = md_link(theme.sidebar.logo.title);
let sub = config.subtitle;
el += layoutTitle(main, url, sub);
let url = md_link(theme.logo.title);
el += layoutTitle(main, url, theme.logo.subtitle);
}
el += '</div>';

View File

@ -1,36 +1,33 @@
<%
// 默认组件
if (page.sidebar == undefined) {
if (page.layout == 'post' && page.content) {
page.sidebar = theme.sidebar.widgets.post;
} else if (page.layout == 'wiki' && page.wiki) {
let proj = theme.wiki.tree[page.wiki];
if (proj?.sidebar) {
page.sidebar = proj.sidebar;
} else {
page.sidebar = theme.sidebar.widgets.wiki;
}
} else if (page.layout === 'topic') {
if (page.topic && theme.topic?.tree[page.topic]?.sidebar) {
page.sidebar = theme.topic.tree[page.topic].sidebar;
} else {
page.sidebar = theme.sidebar.widgets.topic;
}
} else if (page.layout === 'index_topic') {
page.sidebar = theme.sidebar.widgets.index_topic
} else if (is_home()) {
page.sidebar = theme.sidebar.widgets.home;
if (page.sidebar == null) {
const root = theme.root
var sidebar
if (is_home()) {
sidebar = root.home.sidebar
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
page.sidebar = theme.sidebar.widgets.blog_index;
} else if (['wiki_index'].includes(page.layout)) {
page.sidebar = theme.sidebar.widgets.wiki_index;
} else if (['404', undefined].includes(page.layout)) {
page.sidebar = theme.sidebar.widgets.others;
} else if (page.layout == 'page') {
page.sidebar = theme.sidebar.widgets.page;
sidebar = root.blog.sidebar
} else if (page.layout === 'index_topic' || page.layout === 'topic') {
sidebar = root.topic.sidebar
} else if (page.layout === 'index_wiki' || page.layout === 'wiki') {
sidebar = root.wiki.sidebar
} else if (page.layout === '404') {
sidebar = root.error_page.sidebar
} else if (page.layout === null || page.layout === 'page') {
sidebar = root.page.sidebar
} else if (page.layout == 'post') {
sidebar = root.post.sidebar
} else {
page.sidebar = [];
sidebar = []
}
if (page.layout === 'topic' && page.topic && theme.topic?.tree[page.topic]?.sidebar) {
sidebar = theme.topic.tree[page.topic].sidebar
}
if (page.layout == 'wiki' && page.wiki && theme.wiki?.tree[page.wiki]?.sidebar) {
sidebar = theme.wiki.tree[page.wiki].sidebar
}
page.sidebar = sidebar
}
// parse array string
@ -55,25 +52,25 @@ function layoutTitle(main, url, sub) {
}
function layoutWidgets() {
var el = '';
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.tree[page.wiki];
}
el += '<div class="widgets">';
if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') {
el += '<widget class="widget-wrapper logo-wrap wiki"><div class="widget-body">';
// all products
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(config.wiki_dir) + '">';
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(theme.root.wiki.base_dir) + '">';
el += '<svg aria-hidden="true" viewBox="0 0 16 16" width="1.2em" height="1.2em" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>';
el += __('btn.all_wiki');
el += '</a>';
// this product
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.tree[page.wiki];
}
if (proj == undefined) {
// 如果没有项目名则使用menu中显示的名字
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
if (page.menu_id && theme.menu[page.menu_id] && md_link(theme.menu[page.menu_id])) {
proj = {
path: md_link(theme.sidebar.menu[page.menu_id]),
wiki: __(md_text(theme.sidebar.menu[page.menu_id]))
path: md_link(theme.menu[page.menu_id]),
wiki: __(md_text(theme.menu[page.menu_id]))
};
}
}
@ -142,6 +139,7 @@ function layoutFooterDiv() {
return '';
}
}
%>
<% if (page.header == undefined || page.header == 'left' || page.header == 'auto') { %>
<%- partial('header', {where: 'sidebar'}) %>

View File

@ -6,8 +6,8 @@ function layoutDiv() {
el += ' mobile-hidden';
}
el += '">';
for (let id of Object.keys(theme.sidebar.menu)) {
let item = theme.sidebar.menu[id];
for (let id of Object.keys(theme.menu)) {
let item = theme.menu[id];
if (item == undefined || item.length == 0) {
continue;
}

View File

@ -1,25 +1,4 @@
<%
function relatedPosts() {
const { categories } = page;
if (categories.length == 0) {
return ''
}
const relatedItem = categories.data[0]
var el = ''
el += `<widget class="widget-wrapper recent">`
el += `<div class="widget-header cap theme dis-select">`
el += `<span class="name">${__('btn.topic') + __('symbol.colon') + relatedItem.name}</span>`
el += `</div>`
el += `<div class="widget-body related-posts">`
relatedItem.posts.sort('date', -1).each(function(post) {
el += `<a class="item${post.path == page.path ? ' active' : ''}" href="${url_for(post.path)}">`
el += `<span class="title">${post.title}</span>`
el += `</a>`
})
el += `</div>`
el += `</widget>`
return el
}
function relatedPostsInTopic() {
if (page.topic?.length == 0) {
return ''
@ -74,8 +53,6 @@ function relatedWiki() {
function layoutDiv() {
if (page.layout == 'wiki') {
return relatedWiki()
} else if (page.layout == 'post') {
return relatedPosts()
} else if (page.layout == 'topic') {
return relatedPostsInTopic()
}

View File

@ -7,7 +7,7 @@ if (page.menu_id == undefined) {
<% if (site.categories.length) { %>
<% page.title = __('btn.categories'); %>
<% page.layout = 'categories'; %>
<%- partial('_partial/main/navbar/list_post') %>
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
<div class='post-list'>
<article class='<%- scrollreveal() %>' id='cats'>
<% site.categories.sort('path').each(function(category){ %>

View File

@ -1,10 +1,6 @@
<%
if (page.menu_id == undefined) {
if (page.layout === 'wiki_index' && page.wiki) {
page.menu_id = 'wiki';
} else {
page.menu_id = 'post';
}
page.menu_id = 'post';
}
if (page.title && page.wiki) {
page.robots = 'noindex,follow';
@ -48,42 +44,10 @@ function layout_post_list(partial) {
return el;
}
function layout_wiki_list(partial) {
var el = '';
const { shelf, tree } = theme.wiki;
for (let pid of shelf) {
let proj = tree[pid];
if (proj == null) {
continue;
}
if (proj.pages == undefined || proj.pages.length === 0) {
continue;
}
if (page.filter === false) {
// wikiList
el += '<div class="post-list wiki">';
el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>';
} else if (proj.tags && proj.tags.includes(page.tagName) === true) {
// filtered wikiList
el += '<div class="post-list wiki filter">';
el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>';
}
}
return el;
}
%>
<% if (page.menu_id === 'post') { %>
<%- partial('_partial/main/navbar/list_post') %>
<%- layout_post_list(function(post){
return partial('_partial/main/post_list/post_card', {post: post})
}) %>
<%- partial('_partial/main/post_list/paginator') %>
<% } else if (page.menu_id === 'wiki') { %>
<%- partial('_partial/main/navbar/list_wiki') %>
<%- layout_wiki_list(function(proj){
return partial('_partial/main/post_list/wiki_card', {proj: proj})
}) %>
<% } %>
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
<%- layout_post_list(function(post){
return partial('_partial/main/post_list/post_card', {post: post})
}) %>
<%- partial('_partial/main/post_list/paginator') %>

View File

@ -1,12 +1,4 @@
<%
if (page.menu_id == undefined) {
if (page.layout === 'wiki_topic' && page.topic) {
page.menu_id = 'blog'
} else {
page.menu_id = 'post'
}
}
function layout_topic_list(partial) {
var el = ''
const { publish_list, tree } = theme.topic
@ -25,7 +17,7 @@ function layout_topic_list(partial) {
}
function layoutDiv() {
var el = ''
el += partial('_partial/main/navbar/list_post')
el += partial('_partial/main/navbar/nav_tabs_blog')
el += layout_topic_list(function(topic) {
return partial('_partial/main/post_list/topic_card', {topic: topic})
})

42
layout/index_wiki.ejs Normal file
View File

@ -0,0 +1,42 @@
<%
function layout_wiki_list(partial) {
var el = ''
const { shelf, tree } = theme.wiki
for (let pid of shelf) {
let proj = tree[pid]
if (proj == null) {
continue
}
if (proj.pages == undefined || proj.pages.length === 0) {
continue
}
if (page.filter === false) {
// wikiList
el += `<div class="post-list wiki">`
el += `<a class="post-card wiki ${scrollreveal()}" href="${url_for(proj.homepage?.path || '/')}">`
el += partial(proj)
el += `</a>`
el += `</div>`
} else if (proj.tags && proj.tags.includes(page.tagName) === true) {
// filtered wikiList
el += `<div class="post-list wiki filter">`
el += `<a class="post-card wiki ${scrollreveal()}" href="${url_for(proj.homepage?.path || '/')}">`
el += partial(proj)
el += `</a>`
el += `</div>`
}
}
return el
}
function layoutDiv() {
var el = ''
el += partial('_partial/main/navbar/nav_tabs_wiki')
el += layout_wiki_list(function(proj) {
return partial('_partial/main/post_list/wiki_card', {proj: proj})
})
return el
}
%>
<%- layoutDiv() %>

View File

@ -9,8 +9,8 @@ function layoutTitle() {
}
function layoutDiv() {
var el = '';
if (page.post_list) {
el += partial('_partial/main/navbar/list_post');
if (page.nav_tabs) {
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');

View File

@ -7,7 +7,7 @@ if (page.menu_id == undefined) {
<% if (site.tags.length) { %>
<% page.title = __('btn.tags'); %>
<% page.layout = 'tags'; %>
<%- partial('_partial/main/navbar/list_post') %>
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
<div class='post-list'>
<article class='<%- scrollreveal() %>' id='tags'>
<% site.tags.sort('length', -1).each(function(tag){ %>

View File

@ -2,11 +2,8 @@
if (page.menu_id == undefined) {
page.menu_id = 'post'
}
if (page.layout == undefined) {
page.layout = 'index_topic'
}
if (page.title == undefined) {
page.title = __('btn.wiki')
page.title = __('btn.topic')
}
function layoutTitle() {
const title = page.h1 != null ? page.h1 : page.title;
@ -17,23 +14,15 @@ function layoutTitle() {
}
}
%>
<% if (page.layout === 'index_topic') { %>
<%- partial('index') %>
<% } else { %>
<%
if (page.header == undefined) {
page.header = 'auto';
}
%>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content <%- page.layout %><%- page.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- markdown(page.content) %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'topic'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/plugins/comments/layout') %>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content <%- page.layout %><%- page.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- markdown(page.content) %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'topic'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/plugins/comments/layout') %>

View File

@ -2,9 +2,6 @@
if (page.menu_id == undefined) {
page.menu_id = 'wiki';
}
if (page.layout == undefined) {
page.layout = 'wiki_index';
}
if (page.title == undefined) {
if (page.tagName) {
page.title = page.tagName;
@ -21,23 +18,15 @@ function layoutTitle() {
}
}
%>
<% if (page.layout === 'wiki_index') { %>
<%- partial('index') %>
<% } else { %>
<%
if (page.header == undefined) {
page.header = 'auto';
}
%>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content <%- page.layout %><%- page.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- page.content %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'wiki'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/plugins/comments/layout') %>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content <%- page.layout %><%- page.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- page.content %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'wiki'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/plugins/comments/layout') %>

View File

@ -6,7 +6,7 @@
module.exports = ctx => {
var authors = ctx.locals.get('data').authors || {}
let basePath = ctx.config.author_dir || 'author'
let basePath = ctx.theme.config.root.author.base_dir
// url
for (let key of Object.keys(authors)) {
let author = authors[key]

View File

@ -56,8 +56,8 @@ module.exports = hexo => {
hexo.theme.config.data['widgets'] = widgets;
// default menu
if (hexo.theme.config.sidebar.menu == undefined) {
hexo.theme.config.sidebar.menu = [];
if (hexo.theme.config.menu == undefined) {
hexo.theme.config.menu = [];
}
};

View File

@ -177,7 +177,7 @@ module.exports = ctx => {
}
all_tags[tag_name] = {
name: tag_name,
path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/index.html',
path: (ctx.theme.config.root.wiki.base_dir) + '/tags/' + tag_name + '/index.html',
items: items
}
})

View File

@ -3,8 +3,13 @@
*/
hexo.extend.generator.register('404', function (locals) {
const { root } = hexo.theme.config
return {
path: '/404.html',
layout: ['404']
path: root.error_page['404'],
layout: ['404'],
data: {
layout: '404',
menu_id: root.error_page.menu_id
}
}
});
})

View File

@ -3,7 +3,7 @@
*/
hexo.extend.generator.register('author', function (locals) {
const { authors } = hexo.theme.config
const { root, authors } = hexo.theme.config
var pages = []
for (let key of Object.keys(authors)) {
const author = authors[key]
@ -14,7 +14,8 @@ hexo.extend.generator.register('author', function (locals) {
path: author.path,
layout: ['archive'],
data: {
'author': author
author: author,
menu_id: root.author.menu_id
}
})
}

View File

@ -6,10 +6,10 @@ hexo.extend.generator.register('categories', function (locals) {
if (locals.categories && locals.categories.length > 0) {
return {
path: hexo.config.category_dir + '/index.html',
data: locals.posts,
layout: ['categories']
layout: ['categories'],
data: locals.posts
}
} else {
return {};
return {}
}
});
})

View File

@ -6,10 +6,10 @@ hexo.extend.generator.register('tags', function (locals) {
if (locals.tags && locals.tags.length > 0) {
return {
path: hexo.config.tag_dir + '/index.html',
data: locals.posts,
layout: ['tags']
layout: ['tags'],
data: locals.posts
}
} else {
return {};
return {}
}
});
})

View File

@ -3,18 +3,19 @@
*/
hexo.extend.generator.register('topic', function (locals) {
const { topic } = hexo.theme.config
const { root, topic } = hexo.theme.config
const topicIdList = Object.keys(topic.tree)
if (topicIdList.length == 0) {
return {}
}
var ret = []
ret.push({
path: (hexo.theme.config.base_dir.topic) + '/index.html',
path: root.topic.base_dir + '/index.html',
layout: ['index_topic'],
data: {
layout: 'index_topic'
},
layout: ['index_topic']
layout: 'index_topic',
menu_id: root.topic.menu_id
}
})
return ret
})

View File

@ -3,34 +3,35 @@
*/
hexo.extend.generator.register('wiki', function (locals) {
var hasWiki = false;
locals.pages.forEach((page, i) => {
if (page.layout == 'wiki') {
hasWiki = true;
}
});
if (hasWiki) {
var ret = [];
ret.push({
path: (hexo.config.wiki_dir || 'wiki') + '/index.html',
data: {'filter': false},
layout: ['wiki']
});
if (hexo.theme.config.wiki && hexo.theme.config.wiki.all_tags) {
for (let id of Object.keys(hexo.theme.config.wiki.all_tags)) {
let tag = hexo.theme.config.wiki.all_tags[id];
ret.push({
path: tag.path,
data: {
'filter': true,
'tagName': tag.name
},
layout: ['wiki']
});
}
}
return ret;
} else {
return {};
const { root, wiki } = hexo.theme.config
const wikiIdList = Object.keys(wiki.tree)
if (wikiIdList.length == 0) {
return {}
}
});
var ret = []
ret.push({
path: root.wiki.base_dir + '/index.html',
layout: ['index_wiki'],
data: {
layout: 'index_wiki',
menu_id: root.wiki.menu_id,
filter: false
}
})
if (wiki.all_tags) {
for (let id of Object.keys(wiki.all_tags)) {
let tag = wiki.all_tags[id]
ret.push({
path: tag.path,
layout: ['index_wiki'],
data: {
layout: 'index_wiki',
menu_id: root.wiki.menu_id,
filter: true,
tagName: tag.name
}
})
}
}
return ret
})

View File

@ -1,6 +1,6 @@
/**
* md_link(theme.sidebar.menu['home']) is '/'
* md_text(theme.sidebar.menu['home']) is 'Home'
* md_link(theme.menu['home']) is '/'
* md_text(theme.menu['home']) is 'Home'
*/
'use strict';