hexo-theme-stellar 1.39.1 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/stellar-theme-dev/SKILL.md +2 -2
- package/CHANGELOG.md +70 -0
- package/_config.yml +38 -11
- package/_data/icons.yml +250 -37
- package/languages/en.yml +8 -0
- package/languages/zh-CN.yml +8 -0
- package/languages/zh-TW.yml +8 -0
- package/layout/_partial/comments/artalk/script.ejs +26 -1
- package/layout/_partial/comments/beaudar/script.ejs +1 -0
- package/layout/_partial/comments/twikoo/script.ejs +1 -0
- package/layout/_partial/comments/utterances/script.ejs +1 -0
- package/layout/_partial/comments/waline/script.ejs +1 -0
- package/layout/_partial/head.ejs +54 -9
- package/layout/_partial/main/article/article_tags.ejs +16 -0
- package/layout/_partial/main/navbar/article_banner.ejs +17 -0
- package/layout/_partial/main/navbar/dateinfo.ejs +1 -1
- package/layout/_partial/main/notebook/note_card.ejs +1 -1
- package/layout/_partial/main/notebook/paginator.ejs +2 -2
- package/layout/_partial/main/pin_slider.ejs +2 -2
- package/layout/_partial/main/post_list/paginator.ejs +2 -2
- package/layout/_partial/main/post_list/post_card.ejs +11 -0
- package/layout/_partial/menubtn.ejs +2 -2
- package/layout/_partial/scripts/defines.ejs +26 -2
- package/layout/_partial/scripts.ejs +30 -7
- package/layout/_partial/sidebar/logo.ejs +1 -1
- package/layout/_partial/sidebar/menu.ejs +1 -1
- package/layout/_partial/sidebar/search.ejs +1 -1
- package/layout/_partial/widgets/author.ejs +1 -1
- package/layout/_partial/widgets/components/link.ejs +2 -2
- package/layout/_partial/widgets/ghuser.ejs +1 -1
- package/layout/_partial/widgets/markdown.ejs +1 -1
- package/layout/_partial/widgets/related.ejs +1 -1
- package/layout/_partial/widgets/toc.ejs +9 -2
- package/layout/_partial/widgets/tree.ejs +1 -1
- package/layout/_plugins/fancybox.ejs +4 -2
- package/layout/_plugins/mermaid.ejs +2 -1
- package/layout/_plugins/search/local_search.ejs +4 -3
- package/layout/_plugins/swiper.ejs +1 -0
- package/layout/categories.ejs +18 -8
- package/layout/page.ejs +8 -1
- package/layout/tags.ejs +1 -0
- package/package.json +5 -3
- package/scripts/commands/new-note.js +2 -2
- package/scripts/events/lib/doc_tree.js +12 -208
- package/scripts/events/lib/notebooks.js +8 -148
- package/scripts/events/lib/utils.js +10 -1
- package/scripts/filters/index.js +1 -0
- package/scripts/filters/lib/img_lazyload.js +4 -0
- package/scripts/filters/lib/img_onerror.js +4 -0
- package/scripts/filters/lib/md_table.js +46 -0
- package/scripts/generators/search.js +12 -18
- package/scripts/generators/stellar-icons.js +47 -0
- package/scripts/helpers/ai_label.js +29 -0
- package/scripts/helpers/category_tree.js +11 -0
- package/scripts/helpers/icon.js +2 -2
- package/scripts/helpers/json_ld.js +15 -13
- package/scripts/helpers/mdrender.js +29 -0
- package/scripts/helpers/reading_time.js +12 -0
- package/scripts/helpers/related_posts.js +0 -7
- package/scripts/helpers/seo.js +9 -0
- package/scripts/lib/ai_label.js +55 -0
- package/scripts/lib/category_tree.js +26 -0
- package/scripts/lib/doc_tree.js +267 -0
- package/scripts/lib/mdrender_html.js +97 -0
- package/scripts/lib/notebooks.js +181 -0
- package/scripts/lib/reading_time.js +16 -0
- package/scripts/lib/search_index.js +82 -0
- package/scripts/lib/seo.js +79 -0
- package/scripts/lib/wiki_readme.js +57 -0
- package/scripts/tags/index.js +2 -0
- package/scripts/tags/lib/about.js +2 -2
- package/scripts/tags/lib/albums.js +1 -1
- package/scripts/tags/lib/banner.js +1 -1
- package/scripts/tags/lib/chat.js +49 -49
- package/scripts/tags/lib/copy.js +1 -1
- package/scripts/tags/lib/friends.js +1 -1
- package/scripts/tags/lib/gallery.js +1 -1
- package/scripts/tags/lib/hashtag.js +1 -1
- package/scripts/tags/lib/image.js +3 -3
- package/scripts/tags/lib/md.js +17 -9
- package/scripts/tags/lib/posters.js +1 -1
- package/scripts/tags/lib/sites.js +2 -2
- package/scripts/tags/lib/table.js +22 -0
- package/scripts/tags/lib/timeline.js +9 -9
- package/scripts/tags/lib/tip.js +23 -0
- package/source/css/_common/base.styl +5 -9
- package/source/css/_common/device.styl +6 -3
- package/source/css/_components/list.styl +11 -5
- package/source/css/_components/md-table.styl +23 -0
- package/source/css/_components/pages/archives.styl +9 -25
- package/source/css/_components/pages/article-story.styl +4 -4
- package/source/css/_components/partial/article-tags.styl +10 -0
- package/source/css/_components/partial/bread-nav.styl +23 -1
- package/source/css/_components/partial/navbar.styl +10 -2
- package/source/css/_components/sidebar/search.styl +30 -8
- package/source/css/_components/sidebar/sidebar.styl +10 -7
- package/source/css/_components/tag-plugins/table.styl +42 -0
- package/source/css/_components/tag-plugins/tip.styl +27 -0
- package/source/css/_components/widgets/components.styl +6 -0
- package/source/css/_components/widgets/list.styl +6 -0
- package/source/css/_components/widgets/toc.styl +1 -1
- package/source/css/_custom.styl +2 -13
- package/source/css/_defines/func.styl +47 -16
- package/source/css/_defines/theme_base.styl +3 -0
- package/source/css/_plugins/index.styl +0 -18
- package/source/css/{_plugins/comments → comments}/artalk.styl +4 -0
- package/source/css/{_plugins/comments → comments}/twikoo.styl +4 -0
- package/source/css/{_plugins → plugins}/mermaid.styl +3 -0
- package/source/css/{_plugins → plugins}/swiper.styl +5 -1
- package/source/js/icons.js +60 -0
- package/source/js/main.js +206 -1
- package/source/js/search/highlight.js +82 -0
- package/source/js/search/local-search.js +294 -103
- package/source/js/services/mdrender.js +116 -7
- package/source/js/services/memos.js +60 -8
- package/source/js/services/timeline.js +1 -1
- package/source/js/services/waline_latest_comment.js +3 -1
- package/source/js/services/weibo.js +3 -3
- package/source/js/services.js +179 -0
- package/source/js/tagtree.js +29 -0
- package/source/js/theme.js +61 -0
- package/{layout/_partial/scripts/utils.ejs → source/js/utils.js} +13 -10
- package/layout/_partial/scripts/services.ejs +0 -178
- package/layout/_partial/scripts/sidebar.ejs +0 -25
- package/layout/_partial/scripts/tagtree.ejs +0 -29
- package/layout/_partial/scripts/theme.ejs +0 -67
- /package/source/css/{_plugins/comments → comments}/beaudar.styl +0 -0
- /package/source/css/{_plugins/comments → comments}/utterances.styl +0 -0
- /package/source/css/{_plugins/comments → comments}/waline.styl +0 -0
- /package/source/css/{_plugins → plugins}/fancybox.styl +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
utils.initPlugin(() => {
|
|
4
4
|
const els = document.querySelectorAll('.mermaid');
|
|
5
5
|
if (els.length > 0) {
|
|
6
|
+
utils.css(`<%- url_for('/css/plugins/mermaid.css') %>?v=<%- stellar_info('version') %>`);
|
|
6
7
|
const mermaid_config = {
|
|
7
8
|
startOnLoad: false,
|
|
8
9
|
theme:
|
|
@@ -30,4 +31,4 @@
|
|
|
30
31
|
mermaid.run();
|
|
31
32
|
}
|
|
32
33
|
}, 'mermaid');
|
|
33
|
-
</script>
|
|
34
|
+
</script>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
window.addEventListener('DOMContentLoaded', (event) => {
|
|
3
|
-
ctx.search = {
|
|
3
|
+
ctx.search = Object.assign({}, ctx.search, {
|
|
4
4
|
path: `<%- conf.path || '/search.json' %>`,
|
|
5
|
-
|
|
5
|
+
local_search: <%- JSON.stringify(conf) %>,
|
|
6
|
+
});
|
|
6
7
|
utils.js('/js/search/local-search.js', { defer: true });
|
|
7
8
|
});
|
|
8
|
-
</script>
|
|
9
|
+
</script>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
utils.initPlugin(() => {
|
|
3
3
|
const swiper_api = document.getElementById('swiper-api');
|
|
4
4
|
if (swiper_api != undefined) {
|
|
5
|
+
utils.css(`<%- url_for('/css/plugins/swiper.css') %>?v=<%- stellar_info('version') %>`);
|
|
5
6
|
utils.css(`<%- conf.css %>`);
|
|
6
7
|
utils.js(`<%- conf.js %>`, { defer: true }).then(function () {
|
|
7
8
|
const effect = swiper_api.getAttribute('effect') || '';
|
package/layout/categories.ejs
CHANGED
|
@@ -10,14 +10,24 @@ if (page.menu_id == undefined) {
|
|
|
10
10
|
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
|
|
11
11
|
<div class='post-list'>
|
|
12
12
|
<article class='<%- scrollreveal("") %>' id='cats'>
|
|
13
|
-
<%
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
<%
|
|
14
|
+
function renderCategoryTree(nodes) {
|
|
15
|
+
var el = ''
|
|
16
|
+
nodes.forEach(function(node) {
|
|
17
|
+
el += `<div class="cat-item">`
|
|
18
|
+
el += `<a class="cat${node.parentId ? ' child' : ''}" href="${pretty_url(node.path)}">`
|
|
19
|
+
el += `<span class="name">${icon(node.children && node.children.length > 0 ? 'default:category-open' : 'default:category')}${escape_html(node.name)}</span>`
|
|
20
|
+
el += `<span class="badge">(${node.count})</span>`
|
|
21
|
+
el += `</a>`
|
|
22
|
+
if (node.children && node.children.length > 0) {
|
|
23
|
+
el += `<div class="cat-children">${renderCategoryTree(node.children)}</div>`
|
|
24
|
+
}
|
|
25
|
+
el += `</div>`
|
|
26
|
+
})
|
|
27
|
+
return el
|
|
28
|
+
}
|
|
29
|
+
%>
|
|
30
|
+
<%- renderCategoryTree(category_tree(site.categories)) %>
|
|
21
31
|
</article>
|
|
22
32
|
</div>
|
|
23
33
|
<% } %>
|
package/layout/page.ejs
CHANGED
|
@@ -44,14 +44,21 @@ function layoutDiv() {
|
|
|
44
44
|
el += partial('_partial/main/navbar/article_banner')
|
|
45
45
|
}
|
|
46
46
|
el += `<article class="${articleClass()}">`
|
|
47
|
-
if (page.content && page.content.length > 0) {
|
|
47
|
+
if (page.content && String(page.content).trim().length > 0) {
|
|
48
48
|
el += page.content
|
|
49
|
+
} else {
|
|
50
|
+
// wiki 项目首页正文为空(剪裁空白后)且配置了 repo 时,
|
|
51
|
+
// 以该仓库 README.md 作为主页正文(应用层 helper,复用底层远程 md 渲染组件)
|
|
52
|
+
el += wiki_readme_html(theme.wiki.tree[page.wiki], page)
|
|
49
53
|
}
|
|
50
54
|
if (notebook) {
|
|
51
55
|
el += partial('_partial/main/notebook/note_tags', { notebook: notebook })
|
|
52
56
|
}
|
|
53
57
|
el += `</article>`
|
|
54
58
|
if (layout === 'post' || page.wiki || notebook) {
|
|
59
|
+
if (layout === 'post' && theme.article.tags) {
|
|
60
|
+
el += partial('_partial/main/article/article_tags')
|
|
61
|
+
}
|
|
55
62
|
el += partial('_partial/main/article/article_footer')
|
|
56
63
|
}
|
|
57
64
|
if (layout === 'post' || page.wiki) {
|
package/layout/tags.ejs
CHANGED
|
@@ -12,6 +12,7 @@ if (page.menu_id == undefined) {
|
|
|
12
12
|
<article class='<%- scrollreveal("") %>' id='tags'>
|
|
13
13
|
<% site.tags.sort('length', -1).each(function(tag){ %>
|
|
14
14
|
<a class='tag' href="<%= pretty_url(tag.path) %>">
|
|
15
|
+
<%- icon('default:hashtag') %>
|
|
15
16
|
<span class='name'><%= tag.name %></span>
|
|
16
17
|
</a>
|
|
17
18
|
<% }) %>
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hexo-theme-stellar",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Elegant and powerful theme for Hexo.",
|
|
5
5
|
"main": "package.json",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint .",
|
|
8
|
-
"test": "node --test",
|
|
8
|
+
"test": "node ci/check-require-decls.js && node --test",
|
|
9
9
|
"check": "npm run lint && npm test && python3 docs/knowledge/tools/verify.py",
|
|
10
10
|
"release": "node release.js",
|
|
11
11
|
"release:dry": "node release.js --dry-run"
|
|
@@ -29,10 +29,12 @@
|
|
|
29
29
|
"glob": "^10.4.0",
|
|
30
30
|
"hexo-renderer-ejs": "^2.0.0",
|
|
31
31
|
"hexo-renderer-stylus": "^3.0.1",
|
|
32
|
+
"hexo-pagination": "^3.0.0",
|
|
32
33
|
"probe-image-size": "^7.2.3"
|
|
33
34
|
},
|
|
34
35
|
"homepage": "https://xaoxuu.com/wiki/stellar/",
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"eslint": "^9.39.5"
|
|
37
|
+
"eslint": "^9.39.5",
|
|
38
|
+
"hexo-util": "^4.0.0"
|
|
37
39
|
}
|
|
38
40
|
}
|
|
@@ -36,7 +36,7 @@ hexo.extend.console.register('new-note', 'Create a new note', {
|
|
|
36
36
|
const frontMatter = [
|
|
37
37
|
'---',
|
|
38
38
|
`title: ${name}`,
|
|
39
|
-
`date: ${date.getFullYear()}-${String(date.getMonth()+1).padStart(2,'0')}-${String(date.getDate()).padStart(2,'0')} ${String(date.getHours()).padStart(2,'0')}:${String(date.getMinutes()).padStart(2,'0')}
|
|
39
|
+
`date: ${date.getFullYear()}-${String(date.getMonth()+1).padStart(2,'0')}-${String(date.getDate()).padStart(2,'0')} ${String(date.getHours()).padStart(2,'0')}:${String(date.getMinutes()).padStart(2,'0')}`,
|
|
40
40
|
`tags: [${tags.map(t => '"'+t+'"').join(', ')}]`,
|
|
41
41
|
`notebook: ${book}`,
|
|
42
42
|
'---',
|
|
@@ -46,4 +46,4 @@ hexo.extend.console.register('new-note', 'Create a new note', {
|
|
|
46
46
|
fs.writeFileSync(filePath, frontMatter);
|
|
47
47
|
console.log(`Created: ${filePath}`);
|
|
48
48
|
callback();
|
|
49
|
-
});
|
|
49
|
+
});
|
|
@@ -1,216 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* doc_tree.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
|
|
3
|
+
*
|
|
4
|
+
* Wiki 文档树构建入口:委托 scripts/lib/doc_tree.js 的纯函数,
|
|
5
|
+
* 保持 ctx.theme.config.wiki 输出结构与旧实现一致。
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
'use strict';
|
|
6
9
|
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
class WikiPage {
|
|
10
|
-
constructor(page) {
|
|
11
|
-
this.id = page._id
|
|
12
|
-
this.wiki = page.wiki
|
|
13
|
-
this.title = page.title
|
|
14
|
-
this.path = page.path
|
|
15
|
-
this.path_key = normalize_path(page.path)
|
|
16
|
-
this.layout = page.layout
|
|
17
|
-
this.updated = page.updated
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getWikiObject(ctx) {
|
|
22
|
-
var wiki = { tree:{} }
|
|
23
|
-
const data = ctx.locals.get('data')
|
|
24
|
-
var list = []
|
|
25
|
-
for (let key of Object.keys(data)) {
|
|
26
|
-
if (key.endsWith('.DS_Store')) {
|
|
27
|
-
continue
|
|
28
|
-
}
|
|
29
|
-
if (key.includes('wiki/') && key.length > 5) {
|
|
30
|
-
let newKey = key.replace('wiki/', '')
|
|
31
|
-
let obj = data[key]
|
|
32
|
-
if ((typeof obj.tags == 'string') && obj.tags.constructor == String) {
|
|
33
|
-
obj.tags = [obj.tags]
|
|
34
|
-
}
|
|
35
|
-
if ((typeof obj.tree == 'object') && obj.tree.constructor == Array) {
|
|
36
|
-
obj.tree = { '': obj.tree }
|
|
37
|
-
}
|
|
38
|
-
obj.id = newKey
|
|
39
|
-
if (obj.sort == null) {
|
|
40
|
-
obj.sort = 0
|
|
41
|
-
}
|
|
42
|
-
if (obj.base_dir) {
|
|
43
|
-
if (obj.base_dir.startsWith('/')) {
|
|
44
|
-
obj.base_dir = obj.base_dir.substring(1)
|
|
45
|
-
}
|
|
46
|
-
if (obj.base_dir.length > 1 && obj.base_dir.endsWith('/') == false) {
|
|
47
|
-
obj.base_dir = obj.base_dir + '/'
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
obj.base_dir = ''
|
|
51
|
-
}
|
|
52
|
-
list.push(obj)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
list = list.sort((p1, p2) => p2.sort - p1.sort)
|
|
56
|
-
for (let item of list) {
|
|
57
|
-
wiki.tree[item.id] = item
|
|
58
|
-
}
|
|
59
|
-
return wiki
|
|
60
|
-
}
|
|
10
|
+
const { buildWikiTree } = require('../../lib/doc_tree');
|
|
61
11
|
|
|
62
12
|
module.exports = ctx => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// 数据整合:项目标签
|
|
73
|
-
var all_tag_name = []
|
|
74
|
-
for (let id of wiki_list) {
|
|
75
|
-
let item = wiki.tree[id]
|
|
76
|
-
let tags = item.tags
|
|
77
|
-
if (tags) {
|
|
78
|
-
tags.forEach((tag, i) => {
|
|
79
|
-
if (all_tag_name.includes(tag) === false) {
|
|
80
|
-
all_tag_name.push(tag)
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
wiki.tree[id].tags = tags
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 补充项目名称和首页
|
|
88
|
-
for (let id of wiki_list) {
|
|
89
|
-
let item = wiki.tree[id]
|
|
90
|
-
item.id = id
|
|
91
|
-
if (item.title == undefined || item.title.length === 0) {
|
|
92
|
-
item.title = id
|
|
93
|
-
}
|
|
94
|
-
if (item.name == undefined || item.name.length == 0) {
|
|
95
|
-
item.name = id
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 数据整合:每个项目的子页面
|
|
100
|
-
for (let i = 0; i < wiki_list.length; i++) {
|
|
101
|
-
let id = wiki_list[i];
|
|
102
|
-
let item = wiki.tree[id]
|
|
103
|
-
let sub_pages = wiki_pages.filter(p => p.wiki === id)
|
|
104
|
-
|
|
105
|
-
// 首页
|
|
106
|
-
// 未特别指定首页时,获取TOC第一页作为首页
|
|
107
|
-
var homepage = item.homepage
|
|
108
|
-
if (homepage == null && item.tree != null) {
|
|
109
|
-
for (let id of Object.keys(item.tree)) {
|
|
110
|
-
const sec = item.tree[id]
|
|
111
|
-
for (let key of sec) {
|
|
112
|
-
let hs = sub_pages.filter(p => p.path_key == normalize_path(item.base_dir + key))
|
|
113
|
-
if (hs.length > 0) {
|
|
114
|
-
homepage = hs[0]
|
|
115
|
-
break
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (homepage != null) {
|
|
119
|
-
break
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (homepage == null) {
|
|
124
|
-
homepage = sub_pages[0]
|
|
125
|
-
}
|
|
126
|
-
if (typeof homepage == 'string') {
|
|
127
|
-
homepage = {path: homepage}
|
|
128
|
-
}
|
|
129
|
-
homepage.is_homepage = true
|
|
130
|
-
item.homepage = homepage
|
|
131
|
-
// 内页分组
|
|
132
|
-
var sections = []
|
|
133
|
-
var others = sub_pages
|
|
134
|
-
if (item.tree) {
|
|
135
|
-
// 根据配置设置顺序
|
|
136
|
-
for (let title of Object.keys(item.tree)) {
|
|
137
|
-
var sec = { title: title, pages: []}
|
|
138
|
-
for (let key of item.tree[title]) {
|
|
139
|
-
const pagePathKey = normalize_path(item.base_dir + key)
|
|
140
|
-
sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == pagePathKey))
|
|
141
|
-
others = others.filter(p => p.path_key != pagePathKey)
|
|
142
|
-
}
|
|
143
|
-
sections.push(sec)
|
|
144
|
-
}
|
|
145
|
-
if (others.length > 0 && others.filter(p => p.title?.length > 0).length > 0) {
|
|
146
|
-
sections.push({
|
|
147
|
-
title: '...',
|
|
148
|
-
pages: others.sort((p1, p2) => p1.title - p2.title)
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
// 自动设置顺序
|
|
153
|
-
sections.push({
|
|
154
|
-
pages: sub_pages.sort((p1, p2) => p1.title - p2.title)
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// page number
|
|
159
|
-
var page_number = 0
|
|
160
|
-
for (let sec of sections) {
|
|
161
|
-
for (let page of sec.pages) {
|
|
162
|
-
page.page_number = page_number++
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
item.sections = sections
|
|
166
|
-
item.pages = sub_pages
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// 全站所有的项目标签
|
|
170
|
-
var all_tags = {}
|
|
171
|
-
all_tag_name.forEach((tag_name, i) => {
|
|
172
|
-
var items = []
|
|
173
|
-
for (let id of wiki_list) {
|
|
174
|
-
let item = wiki.tree[id]
|
|
175
|
-
// 过滤掉找不到页面的项目
|
|
176
|
-
if (item.homepage == null) {
|
|
177
|
-
continue
|
|
178
|
-
}
|
|
179
|
-
// 过滤掉未上架的项目
|
|
180
|
-
if (!wiki.shelf.includes(item.id)) {
|
|
181
|
-
continue
|
|
182
|
-
}
|
|
183
|
-
if (item.tags && item.tags.includes(tag_name) === true && items.includes(tag_name) === false) {
|
|
184
|
-
items.push(item.id)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
all_tags[tag_name] = {
|
|
188
|
-
name: tag_name,
|
|
189
|
-
path: (ctx.theme.config.site_tree.index_wiki.base_dir) + '/tags/' + tag_name + '/index.html',
|
|
190
|
-
items: items
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// 关联相似项目
|
|
195
|
-
for (let id of wiki_list) {
|
|
196
|
-
let item = wiki.tree[id]
|
|
197
|
-
if (item.tags) {
|
|
198
|
-
var relatedItems = []
|
|
199
|
-
item.tags.forEach((tag_name, i) => {
|
|
200
|
-
let relatedOtherItems = all_tags[tag_name].items.filter(name => name != item.id)
|
|
201
|
-
if (relatedOtherItems.length > 0) {
|
|
202
|
-
relatedItems.push({
|
|
203
|
-
name: tag_name,
|
|
204
|
-
items: relatedOtherItems
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
|
-
item.relatedItems = relatedItems
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
wiki.all_tags = all_tags
|
|
213
|
-
wiki.all_pages = wiki_pages
|
|
214
|
-
ctx.theme.config.wiki = wiki
|
|
215
|
-
|
|
216
|
-
}
|
|
13
|
+
const wiki = buildWikiTree({
|
|
14
|
+
data: ctx.locals.get('data'),
|
|
15
|
+
pages: ctx.locals.get('pages'),
|
|
16
|
+
shelf: ctx.locals.get('data').wiki || [],
|
|
17
|
+
siteTree: ctx.theme.config.site_tree
|
|
18
|
+
});
|
|
19
|
+
ctx.theme.config.wiki = wiki;
|
|
20
|
+
};
|
|
@@ -1,155 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* notebooks.js v1
|
|
3
|
+
*
|
|
4
|
+
* 笔记本系统构建入口:委托 scripts/lib/notebooks.js 的纯函数,
|
|
5
|
+
* 保持 ctx.theme.config.notebooks 输出结构与旧实现一致。
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
|
-
'use strict'
|
|
8
|
+
'use strict';
|
|
6
9
|
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
class NotePage {
|
|
10
|
-
constructor(page) {
|
|
11
|
-
this.id = page._id
|
|
12
|
-
this.notebook = page.notebook
|
|
13
|
-
this.title = page.title
|
|
14
|
-
this.tags = page.tags
|
|
15
|
-
this.path = page.path
|
|
16
|
-
this.path_key = normalize_path(page.path)
|
|
17
|
-
this.layout = page.layout
|
|
18
|
-
this.date = page.date
|
|
19
|
-
this.updated = page.updated || page.date
|
|
20
|
-
|
|
21
|
-
const pin = page.pin ?? page.sticky ?? 0
|
|
22
|
-
if (pin === true) {
|
|
23
|
-
this.pin = 1
|
|
24
|
-
} else if (pin === false) {
|
|
25
|
-
this.pin = 0
|
|
26
|
-
} else {
|
|
27
|
-
this.pin = pin
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function splitTag(tag) {
|
|
33
|
-
return tag.split('/').filter(t => t.length > 0)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function prepareNotebook(id, info, ctx) {
|
|
37
|
-
const notebook = info
|
|
38
|
-
notebook.id = id
|
|
39
|
-
|
|
40
|
-
if (notebook.base_dir) {
|
|
41
|
-
if (notebook.base_dir.startsWith('/')) {
|
|
42
|
-
notebook.base_dir = notebook.base_dir.substring(1)
|
|
43
|
-
}
|
|
44
|
-
if (notebook.base_dir.length > 1 && !notebook.base_dir.endsWith('/')) {
|
|
45
|
-
notebook.base_dir = notebook.base_dir + '/'
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
const notebooksBaseDir = ctx.theme.config.site_tree.notebooks.base_dir
|
|
49
|
-
notebook.base_dir = notebooksBaseDir ? `${notebooksBaseDir}/${id}` : id
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
notebook.sort ||= 0
|
|
53
|
-
notebook.auto_excerpt ||= ctx.theme.config.notebook.auto_excerpt || 0
|
|
54
|
-
notebook.per_page ??= ctx.theme.config.notebook.per_page ?? ctx.config.per_page ?? 10
|
|
55
|
-
notebook.order_by ||= ctx.theme.config.notebook.order_by || '-updated'
|
|
56
|
-
notebook.menu_id ??= ctx.theme.config.site_tree.notes.menu_id
|
|
57
|
-
notebook.license ??= ctx.theme.config.notebook.license
|
|
58
|
-
notebook.share ??= ctx.theme.config.notebook.share
|
|
59
|
-
|
|
60
|
-
notebook.leftbar ??= ctx.theme.config.site_tree.notes.leftbar
|
|
61
|
-
notebook.rightbar ??= ctx.theme.config.site_tree.notes.rightbar
|
|
62
|
-
notebook.note_leftbar ??= ctx.theme.config.site_tree.note.leftbar
|
|
63
|
-
notebook.note_rightbar ??= ctx.theme.config.site_tree.note.rightbar
|
|
64
|
-
|
|
65
|
-
const tagMap = new Map() // tagId: tagInfo
|
|
66
|
-
notebook.tagTree = tagMap
|
|
67
|
-
|
|
68
|
-
const rootTag = {
|
|
69
|
-
id: '',
|
|
70
|
-
name: '',
|
|
71
|
-
part: '',
|
|
72
|
-
path: notebook.base_dir,
|
|
73
|
-
parent: null, // parent tag id
|
|
74
|
-
childSet: new Set(), // child tag ids
|
|
75
|
-
noteSet: new Set(), // note ids
|
|
76
|
-
}
|
|
77
|
-
tagMap.set(rootTag.id, rootTag)
|
|
78
|
-
|
|
79
|
-
// Iterate through all notes in the notebook, build the tag tree.
|
|
80
|
-
const allPages = ctx.locals.get('pages')
|
|
81
|
-
const pages = allPages.filter(p => p.notebook === notebook.id)
|
|
82
|
-
for (const page of pages.data) {
|
|
83
|
-
rootTag.noteSet.add(page._id)
|
|
84
|
-
|
|
85
|
-
if (!page.tags) {
|
|
86
|
-
continue
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (const hierarchyTag of page.tags) {
|
|
90
|
-
const parts = splitTag(hierarchyTag)
|
|
91
|
-
let parent = rootTag
|
|
92
|
-
for (const part of parts) {
|
|
93
|
-
const tagName = parent.name ? `${parent.name}/${part}` : part
|
|
94
|
-
const tagId = tagName.toLowerCase()
|
|
95
|
-
let tag = tagMap.get(tagId)
|
|
96
|
-
if (tag == null) {
|
|
97
|
-
tag = {
|
|
98
|
-
id: tagId,
|
|
99
|
-
name: tagName,
|
|
100
|
-
part: part,
|
|
101
|
-
path: `${notebook.base_dir}/tags/${tagId}`,
|
|
102
|
-
parent: parent.id,
|
|
103
|
-
childSet: new Set(),
|
|
104
|
-
noteSet: new Set(),
|
|
105
|
-
}
|
|
106
|
-
tagMap.set(tagId, tag)
|
|
107
|
-
parent.childSet.add(tagId)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
tag.noteSet.add(page._id)
|
|
111
|
-
parent = tag
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
notebook.noteMap = pages.map(p => new NotePage(p)).reduce((map, note) => {
|
|
117
|
-
map.set(note.id, note)
|
|
118
|
-
return map
|
|
119
|
-
}, new Map())
|
|
120
|
-
|
|
121
|
-
// Sort child tags for each tag.
|
|
122
|
-
for (const [_, tag] of tagMap) {
|
|
123
|
-
tag.children = Array.from(tag.childSet)
|
|
124
|
-
tag.children.sort()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return notebook
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function getNotebooksObject(ctx) {
|
|
131
|
-
const notebooks = {
|
|
132
|
-
tree: {},
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const data = ctx.locals.get('data')
|
|
136
|
-
const list = []
|
|
137
|
-
for (const [key, info] of Object.entries(data)) {
|
|
138
|
-
if (!key.startsWith('notebooks/') || key.endsWith('.DS_Store')) {
|
|
139
|
-
continue
|
|
140
|
-
}
|
|
141
|
-
const id = key.substring(10)
|
|
142
|
-
list.push(prepareNotebook(id, info, ctx))
|
|
143
|
-
}
|
|
144
|
-
list.sort((a, b) => a.sort - b.sort)
|
|
145
|
-
for (const info of list) {
|
|
146
|
-
notebooks.tree[info.id] = info
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return notebooks
|
|
150
|
-
}
|
|
10
|
+
const { getNotebooksObject } = require('../../lib/notebooks');
|
|
151
11
|
|
|
152
12
|
module.exports = ctx => {
|
|
153
|
-
const notebooks = getNotebooksObject(ctx)
|
|
154
|
-
ctx.theme.config.notebooks = notebooks
|
|
155
|
-
}
|
|
13
|
+
const notebooks = getNotebooksObject(ctx);
|
|
14
|
+
ctx.theme.config.notebooks = notebooks;
|
|
15
|
+
};
|
|
@@ -71,7 +71,7 @@ module.exports = hexo => {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
hexo.utils = {
|
|
74
|
-
icon: (key, args) => {
|
|
74
|
+
icon: (key, args, inline) => {
|
|
75
75
|
const { icons } = hexo.theme.config
|
|
76
76
|
var result = ''
|
|
77
77
|
if (icons[key]) {
|
|
@@ -81,9 +81,18 @@ module.exports = hexo => {
|
|
|
81
81
|
}
|
|
82
82
|
if (result.startsWith('/') || result.startsWith('https://') || result.startsWith('http://')) {
|
|
83
83
|
return `<img ${args?.length > 0 ? args : ''} src="${result}" />`
|
|
84
|
+
} else if (inline === true) {
|
|
85
|
+
return result
|
|
86
|
+
} else if (result.startsWith('<svg')) {
|
|
87
|
+
// 非首屏图标:输出占位符,由 /js/icons.js 异步拉取 js/icons/{ns}.json 后原位替换
|
|
88
|
+
return `<svg class="icon" data-icon="${key}" aria-hidden="true"></svg>`
|
|
84
89
|
} else {
|
|
85
90
|
return result
|
|
86
91
|
}
|
|
92
|
+
},
|
|
93
|
+
iconData: (key) => {
|
|
94
|
+
const { icons } = hexo.theme.config
|
|
95
|
+
return icons && icons[key] ? icons[key] : ''
|
|
87
96
|
}
|
|
88
97
|
};
|
|
89
98
|
};
|
package/scripts/filters/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
hexo.extend.filter.register('after_render:html', require('./lib/img_lazyload').processSite);
|
|
4
4
|
hexo.extend.filter.register('after_render:html', require('./lib/img_onerror').processSite);
|
|
5
|
+
hexo.extend.filter.register('after_post_render', require('./lib/md_table').processPost);
|
|
5
6
|
|
|
6
7
|
function change_image(data) {
|
|
7
8
|
if (this.theme.config.tag_plugins.image.parse_markdown) {
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
// 懒加载强制开启:不再读取 enable 配置,no-lazy 是唯一例外
|
|
9
9
|
function lazyProcess(htmlContent) {
|
|
10
|
+
// 短路:无 <img 的页面(如 404)无需正则扫描
|
|
11
|
+
if (typeof htmlContent !== 'string' || !/<img/i.test(htmlContent)) {
|
|
12
|
+
return htmlContent;
|
|
13
|
+
}
|
|
10
14
|
return htmlContent.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, function(imgTag, src_before, src_value, src_after) {
|
|
11
15
|
// 已由 tag 插件输出懒加载标记(data-src / data-srcset)的图片不重复处理
|
|
12
16
|
if (/data-src/gi.test(imgTag)) {
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
module.exports.processSite = function(htmlContent) {
|
|
9
|
+
// 短路:无 <img 的页面(如 404)无需正则扫描
|
|
10
|
+
if (typeof htmlContent !== 'string' || !/<img/i.test(htmlContent)) {
|
|
11
|
+
return htmlContent;
|
|
12
|
+
}
|
|
9
13
|
const default_image = this.theme.config.default.image;
|
|
10
14
|
return htmlContent.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, function(imgTag) {
|
|
11
15
|
if (/="data:image(.*?)/gi.test(imgTag)) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* md_table.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
|
|
3
|
+
* 普通 Markdown 表格包一层 .md-table-scroll 横向滚动容器,
|
|
4
|
+
* 宽度足够时铺满容器,内容超出容器宽度时横向滚动。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const cheerio = require('cheerio');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 将内容中的普通 `<table>` 包一层 `.md-table-scroll` 容器。
|
|
13
|
+
* 排除代码高亮表格(.highlight)与 {% table %} 标签容器(.tag-plugin.table)。
|
|
14
|
+
*/
|
|
15
|
+
function wrapMdTables(htmlContent) {
|
|
16
|
+
// 短路:不含 <table 时无需解析,避免 cheerio 全量 parse + serialize
|
|
17
|
+
if (typeof htmlContent === 'string' && !htmlContent.includes('<table')) {
|
|
18
|
+
return htmlContent;
|
|
19
|
+
}
|
|
20
|
+
const $ = cheerio.load(htmlContent, null, false);
|
|
21
|
+
$('table').each(function () {
|
|
22
|
+
const $table = $(this);
|
|
23
|
+
if ($table.parent().is('.md-table-scroll')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if ($table.closest('.highlight').length) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if ($table.closest('.tag-plugin.table').length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
$table.wrap('<div class="md-table-scroll"></div>');
|
|
33
|
+
});
|
|
34
|
+
return $.html();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports.wrapMdTables = wrapMdTables;
|
|
38
|
+
|
|
39
|
+
function processPost(data) {
|
|
40
|
+
if (data.content) {
|
|
41
|
+
data.content = wrapMdTables(data.content);
|
|
42
|
+
}
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports.processPost = processPost;
|