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
|
@@ -2,29 +2,11 @@
|
|
|
2
2
|
@import 'aplayer'
|
|
3
3
|
|
|
4
4
|
// 根据主题配置加载
|
|
5
|
-
if hexo-config('plugins.swiper.enable')
|
|
6
|
-
@import 'swiper'
|
|
7
5
|
if hexo-config('plugins.scrollreveal.enable')
|
|
8
6
|
@import 'scrollreveal'
|
|
9
|
-
if hexo-config('plugins.fancybox.enable')
|
|
10
|
-
@import 'fancybox'
|
|
11
|
-
if hexo-config('plugins.mermaid.style_optimization')
|
|
12
|
-
@import 'mermaid'
|
|
13
7
|
if hexo-config('plugins.copycode.enable')
|
|
14
8
|
@import 'copycode'
|
|
15
9
|
if hexo-config('plugins.tianli_gpt.enable')
|
|
16
10
|
@import 'tianli_gpt'
|
|
17
11
|
if hexo-config('plugins.katex.enable')
|
|
18
12
|
@import 'katex'
|
|
19
|
-
|
|
20
|
-
// 评论
|
|
21
|
-
if hexo-config('comments.service') == 'beaudar' or index(hexo-config('comments.custom_css'), 'beaudar') >= 0
|
|
22
|
-
@import 'comments/beaudar'
|
|
23
|
-
if hexo-config('comments.service') == 'twikoo' or index(hexo-config('comments.custom_css'), 'twikoo') >= 0
|
|
24
|
-
@import 'comments/twikoo'
|
|
25
|
-
if hexo-config('comments.service') == 'utterances' or index(hexo-config('comments.custom_css'), 'utterances') >= 0
|
|
26
|
-
@import 'comments/utterances'
|
|
27
|
-
if hexo-config('comments.service') == 'waline' or index(hexo-config('comments.custom_css'), 'waline') >= 0
|
|
28
|
-
@import 'comments/waline'
|
|
29
|
-
if hexo-config('comments.service') == 'artalk' or index(hexo-config('comments.custom_css'), 'artalk') >= 0
|
|
30
|
-
@import 'comments/artalk'
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
@import '../_defines/const'
|
|
2
|
+
@import '../_custom'
|
|
3
|
+
@import '../_defines/func'
|
|
4
|
+
|
|
1
5
|
:root
|
|
2
6
|
--swiper-theme-color: var(--theme) !important
|
|
3
7
|
.swiper
|
|
@@ -53,4 +57,4 @@ div.swiper-slide
|
|
|
53
57
|
transform: translateX(-1px)
|
|
54
58
|
|
|
55
59
|
.swiper-button-next:after
|
|
56
|
-
transform: translateX(1px)
|
|
60
|
+
transform: translateX(1px)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* icons.js | 非首屏图标异步加载
|
|
3
|
+
*
|
|
4
|
+
* 服务端 icon() 对非首屏 SVG 图标输出 <svg class="icon" data-icon="ns:key"> 占位符,
|
|
5
|
+
* 本脚本按命名空间拉取构建期生成的 js/icons/{ns}.json,成功后原位替换为完整内联 SVG,
|
|
6
|
+
* 最终 DOM 与全量内联一致,现有 CSS 钩子(搜索三态、菜单渐变、chat 着色等)不受影响。
|
|
7
|
+
* 首屏关键图标(搜索、菜单、leftbar/rightbar、goback)由模板内联,不经过本脚本。
|
|
8
|
+
*/
|
|
9
|
+
(function () {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const nodes = Array.prototype.slice.call(document.querySelectorAll('svg.icon[data-icon]'));
|
|
13
|
+
if (nodes.length === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const groups = {};
|
|
18
|
+
nodes.forEach((node) => {
|
|
19
|
+
const key = node.getAttribute('data-icon');
|
|
20
|
+
const idx = key.indexOf(':');
|
|
21
|
+
if (idx < 1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const ns = key.slice(0, idx);
|
|
25
|
+
if (!groups[ns]) {
|
|
26
|
+
groups[ns] = [];
|
|
27
|
+
}
|
|
28
|
+
groups[ns].push(node);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const script = document.currentScript;
|
|
32
|
+
const version = (script && script.getAttribute('data-version')) || '';
|
|
33
|
+
const root = (typeof ctx !== 'undefined' && ctx.root) || '/';
|
|
34
|
+
|
|
35
|
+
Object.keys(groups).forEach((ns) => {
|
|
36
|
+
const url = root + 'js/icons/' + ns + '.json' + (version ? '?v=' + version : '');
|
|
37
|
+
fetch(url)
|
|
38
|
+
.then((res) => {
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
throw new Error('HTTP ' + res.status);
|
|
41
|
+
}
|
|
42
|
+
return res.json();
|
|
43
|
+
})
|
|
44
|
+
.then((data) => {
|
|
45
|
+
const set = data && data[ns];
|
|
46
|
+
groups[ns].forEach((node) => {
|
|
47
|
+
const key = node.getAttribute('data-icon');
|
|
48
|
+
const svg = set && set[key];
|
|
49
|
+
if (typeof svg === 'string' && svg.length > 0) {
|
|
50
|
+
node.outerHTML = svg;
|
|
51
|
+
} else {
|
|
52
|
+
console.warn('[stellar] icon not found: ' + key);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
console.warn('[stellar] icons load failed: ' + ns, err);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
})();
|
package/source/js/main.js
CHANGED
|
@@ -97,6 +97,30 @@ const hud = {
|
|
|
97
97
|
|
|
98
98
|
const l_body = document.querySelector('.l_body');
|
|
99
99
|
|
|
100
|
+
const sidebar = {
|
|
101
|
+
leftbar: () => {
|
|
102
|
+
if (l_body) {
|
|
103
|
+
l_body.toggleAttribute('leftbar');
|
|
104
|
+
l_body.removeAttribute('rightbar');
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
rightbar: () => {
|
|
108
|
+
if (l_body) {
|
|
109
|
+
l_body.toggleAttribute('rightbar');
|
|
110
|
+
l_body.removeAttribute('leftbar');
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
dismiss: () => {
|
|
114
|
+
if (l_body) {
|
|
115
|
+
l_body.removeAttribute('leftbar');
|
|
116
|
+
l_body.removeAttribute('rightbar');
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
toggleTOC: () => {
|
|
120
|
+
document.querySelector('#data-toc').classList.toggle('collapse');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
100
124
|
// 通用平滑滚动(自定义动画,TOC / 回到顶部 / 参与讨论共用)
|
|
101
125
|
let scrollAnim = null;
|
|
102
126
|
function cancelSmoothScroll() {
|
|
@@ -132,14 +156,139 @@ function smoothScrollTo(targetY) {
|
|
|
132
156
|
window.addEventListener('wheel', cancelSmoothScroll, { passive: true });
|
|
133
157
|
window.addEventListener('touchstart', cancelSmoothScroll, { passive: true });
|
|
134
158
|
|
|
159
|
+
// 远程 md(mdrender 服务)渲染完成后重建右栏 TOC:结构与服务端 toc() 输出一致
|
|
160
|
+
let tocClickBound = false;
|
|
161
|
+
function rebuildToc(scope) {
|
|
162
|
+
const widget = document.querySelector('#data-toc');
|
|
163
|
+
if (!widget) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const body = widget.querySelector('.widget-body');
|
|
167
|
+
if (!body) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const article = scope && scope.closest ? scope.closest('article.md-text') : null;
|
|
171
|
+
const root = article || document.querySelector('article.md-text');
|
|
172
|
+
if (!root) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const headings = root.querySelectorAll('h1,h2,h3,h4,h5,h6');
|
|
176
|
+
if (headings.length === 0) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const ol = document.createElement('ol');
|
|
180
|
+
ol.className = 'toc';
|
|
181
|
+
const stack = [];
|
|
182
|
+
headings.forEach(function (h) {
|
|
183
|
+
const id = h.id;
|
|
184
|
+
if (!id) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const level = parseInt(h.tagName.substring(1), 10);
|
|
188
|
+
const li = document.createElement('li');
|
|
189
|
+
li.className = 'toc-item toc-level-' + level;
|
|
190
|
+
const a = document.createElement('a');
|
|
191
|
+
a.className = 'toc-link';
|
|
192
|
+
a.href = '#' + encodeURIComponent(id);
|
|
193
|
+
const span = document.createElement('span');
|
|
194
|
+
span.className = 'toc-text';
|
|
195
|
+
span.textContent = h.textContent.trim();
|
|
196
|
+
a.appendChild(span);
|
|
197
|
+
li.appendChild(a);
|
|
198
|
+
while (stack.length > 0 && stack[stack.length - 1].level >= level) {
|
|
199
|
+
stack.pop();
|
|
200
|
+
}
|
|
201
|
+
if (stack.length === 0) {
|
|
202
|
+
ol.appendChild(li);
|
|
203
|
+
} else {
|
|
204
|
+
const parent = stack[stack.length - 1];
|
|
205
|
+
if (!parent.childOl) {
|
|
206
|
+
parent.childOl = document.createElement('ol');
|
|
207
|
+
parent.childOl.className = 'toc-child';
|
|
208
|
+
parent.li.appendChild(parent.childOl);
|
|
209
|
+
}
|
|
210
|
+
parent.childOl.appendChild(li);
|
|
211
|
+
}
|
|
212
|
+
stack.push({ level: level, li: li });
|
|
213
|
+
});
|
|
214
|
+
body.innerHTML = '';
|
|
215
|
+
body.appendChild(ol);
|
|
216
|
+
bindTocClick(widget);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function bindTocClick(widget) {
|
|
220
|
+
if (tocClickBound) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
tocClickBound = true;
|
|
224
|
+
widget.addEventListener('click', function (e) {
|
|
225
|
+
const link = e.target.closest('a.toc-link');
|
|
226
|
+
if (!link) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const href = link.getAttribute('href');
|
|
230
|
+
const id = href && href.indexOf('#') === 0 ? decodeURIComponent(href.slice(1)) : null;
|
|
231
|
+
const target = id && document.getElementById(id);
|
|
232
|
+
if (target) {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
const offset = 32;
|
|
235
|
+
const targetY = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
236
|
+
smoothScrollTo(targetY);
|
|
237
|
+
if (window.history && window.history.pushState) {
|
|
238
|
+
window.history.pushState(null, '', href);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 通用页内锚点平滑滚动(标题左侧 headerlink、{% navbar %} 页内导航、脚注回链等)
|
|
245
|
+
// 已被其他处理器拦截的点击(TOC、tabs、wiki #start 等)通过 defaultPrevented 跳过,避免重复滚动
|
|
246
|
+
function bindAnchorClick() {
|
|
247
|
+
document.addEventListener('click', function (e) {
|
|
248
|
+
const link = e.target.closest('a[href^="#"]');
|
|
249
|
+
if (!link || e.defaultPrevented) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const href = link.getAttribute('href');
|
|
253
|
+
if (!href || href.indexOf('#') !== 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
let id = href.slice(1);
|
|
257
|
+
try {
|
|
258
|
+
id = decodeURIComponent(id);
|
|
259
|
+
} catch (err) {
|
|
260
|
+
// 片段含非法编码时按原样查找
|
|
261
|
+
}
|
|
262
|
+
const target = id && document.getElementById(id);
|
|
263
|
+
if (!target) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
// #start 锚点贴顶滚动,不预留 offset;其余锚点与 TOC 点击滚动保持一致(32px)
|
|
268
|
+
const offset = id === 'start' ? 0 : 32;
|
|
269
|
+
const targetY = target.getBoundingClientRect().top + window.scrollY - offset;
|
|
270
|
+
smoothScrollTo(targetY);
|
|
271
|
+
if (window.history && window.history.pushState) {
|
|
272
|
+
window.history.pushState(null, '', href);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
bindAnchorClick();
|
|
277
|
+
|
|
278
|
+
// 远程 md 渲染完成后由页面层重建右栏 TOC
|
|
279
|
+
document.addEventListener('stellar:mdrender', function (e) {
|
|
280
|
+
rebuildToc(e.detail && e.detail.target);
|
|
281
|
+
});
|
|
282
|
+
|
|
135
283
|
|
|
136
284
|
const init = {
|
|
137
285
|
toc: () => {
|
|
138
286
|
const scrollOffset = 32;
|
|
139
287
|
// 滚动位置取整后标题顶可能落在偏移线下方 1~2px,加容差避免高亮回跳到上一条
|
|
140
288
|
const scrollTolerance = 4;
|
|
141
|
-
var segs = utils.qsa("article.md-text h1, article.md-text h2, article.md-text h3, article.md-text h4, article.md-text h5, article.md-text h6");
|
|
142
289
|
function activeTOC() {
|
|
290
|
+
// 每次滚动动态查询:远程 md 内容渲染后标题才存在
|
|
291
|
+
var segs = utils.qsa("article.md-text h1, article.md-text h2, article.md-text h3, article.md-text h4, article.md-text h5, article.md-text h6");
|
|
143
292
|
var scrollTop = window.scrollY;
|
|
144
293
|
var topSeg = null;
|
|
145
294
|
for (var i = 0; i < segs.length; i++) {
|
|
@@ -276,6 +425,61 @@ const init = {
|
|
|
276
425
|
}
|
|
277
426
|
} catch (e) {}
|
|
278
427
|
},
|
|
428
|
+
navbarPin: () => {
|
|
429
|
+
// 列表页 navbar top 背景条状态切换:未吸顶为卡片样式(var(--card) + 文章卡片同款阴影),
|
|
430
|
+
// 吸顶后恢复玻璃效果。在吸顶边界切换 .pinned 类,视觉由 CSS 控制。
|
|
431
|
+
// 吸顶判定直接测 navbar 的实际视口位置,而非用 scrollY 推算:
|
|
432
|
+
// 移动端浏览器顶栏伸缩会改变 scrollY(展开顶栏时 scrollY 减小),
|
|
433
|
+
// 即使 navbar 仍吸顶也可能跌破阈值,导致玻璃效果误消失。
|
|
434
|
+
const navbars = document.querySelectorAll('.navbar.top');
|
|
435
|
+
if (navbars.length === 0) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
// 视口顶部允许的偏差(px),吸收亚像素/取整误差
|
|
439
|
+
const TOLERANCE = 2;
|
|
440
|
+
let states = [];
|
|
441
|
+
function update() {
|
|
442
|
+
states.forEach((state) => {
|
|
443
|
+
const top = state.navbar.getBoundingClientRect().top;
|
|
444
|
+
state.bar.classList.toggle('pinned', top <= state.stickyTop + TOLERANCE);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function measure() {
|
|
448
|
+
states = [];
|
|
449
|
+
navbars.forEach((navbar) => {
|
|
450
|
+
const bar = navbar.querySelector('.navbar-blur');
|
|
451
|
+
if (bar == null) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
// getComputedStyle().top 自动兼容桌面 var(--gap-margin) 与移动端 8pt
|
|
455
|
+
const stickyTop = parseFloat(getComputedStyle(navbar).top) || 16;
|
|
456
|
+
states.push({
|
|
457
|
+
navbar: navbar,
|
|
458
|
+
bar: bar,
|
|
459
|
+
stickyTop: stickyTop
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
update();
|
|
463
|
+
}
|
|
464
|
+
let ticking = false;
|
|
465
|
+
window.addEventListener('scroll', () => {
|
|
466
|
+
if (ticking) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
ticking = true;
|
|
470
|
+
utils.requestAnimationFrame(() => {
|
|
471
|
+
update();
|
|
472
|
+
ticking = false;
|
|
473
|
+
});
|
|
474
|
+
}, { passive: true });
|
|
475
|
+
// 顶栏伸缩不一定触发 scroll,兜底监听 visualViewport 尺寸变化
|
|
476
|
+
if (window.visualViewport) {
|
|
477
|
+
window.visualViewport.addEventListener('resize', update);
|
|
478
|
+
}
|
|
479
|
+
window.addEventListener('resize', measure);
|
|
480
|
+
window.addEventListener('pageshow', measure);
|
|
481
|
+
measure();
|
|
482
|
+
},
|
|
279
483
|
relativeDate: (selector) => {
|
|
280
484
|
selector.forEach(item => {
|
|
281
485
|
const $this = item
|
|
@@ -418,6 +622,7 @@ stellar.initPage = function () {
|
|
|
418
622
|
init.sidebar();
|
|
419
623
|
init.wikiStart();
|
|
420
624
|
init.leftbarScroll();
|
|
625
|
+
init.navbarPin();
|
|
421
626
|
init.relativeDate(document.querySelectorAll('#post-meta time'));
|
|
422
627
|
init.registerTabsTag();
|
|
423
628
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// 搜索跳转高亮:URL 带 ?kw= 时在正文中高亮匹配词
|
|
2
|
+
(function () {
|
|
3
|
+
var params;
|
|
4
|
+
try {
|
|
5
|
+
params = new URLSearchParams(window.location.search);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
var keyword = (params.get('kw') || '').trim();
|
|
10
|
+
if (!keyword) return;
|
|
11
|
+
|
|
12
|
+
function escapeRegExp(string) {
|
|
13
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function highlightKeyword() {
|
|
17
|
+
// 优先主栏正文(避免命中 wiki 封面等其它 md-text 容器)
|
|
18
|
+
var root = document.querySelector('.l_main .md-text') || document.querySelector('.md-text');
|
|
19
|
+
if (!root) return;
|
|
20
|
+
|
|
21
|
+
var re = new RegExp(escapeRegExp(keyword), 'gi');
|
|
22
|
+
var textNodes = [];
|
|
23
|
+
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
|
24
|
+
acceptNode: function (node) {
|
|
25
|
+
var parent = node.parentElement;
|
|
26
|
+
if (!parent) return NodeFilter.FILTER_REJECT;
|
|
27
|
+
// 跳过脚本/样式内容与已存在的 mark 高亮
|
|
28
|
+
if (parent.closest('script, style, noscript, .tag-plugin.mark')) {
|
|
29
|
+
return NodeFilter.FILTER_REJECT;
|
|
30
|
+
}
|
|
31
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
var node;
|
|
35
|
+
while ((node = walker.nextNode())) {
|
|
36
|
+
textNodes.push(node);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var limit = 50;
|
|
40
|
+
var count = 0;
|
|
41
|
+
for (var i = 0; i < textNodes.length && count < limit; i++) {
|
|
42
|
+
var textNode = textNodes[i];
|
|
43
|
+
var text = textNode.nodeValue || '';
|
|
44
|
+
var frag = document.createDocumentFragment();
|
|
45
|
+
var lastIndex = 0;
|
|
46
|
+
var m;
|
|
47
|
+
re.lastIndex = 0;
|
|
48
|
+
while (count < limit && (m = re.exec(text)) !== null) {
|
|
49
|
+
if (m.index > lastIndex) {
|
|
50
|
+
frag.appendChild(document.createTextNode(text.slice(lastIndex, m.index)));
|
|
51
|
+
}
|
|
52
|
+
var mark = document.createElement('mark');
|
|
53
|
+
mark.className = 'tag-plugin colorful mark';
|
|
54
|
+
mark.setAttribute('color', 'yellow');
|
|
55
|
+
mark.textContent = m[0];
|
|
56
|
+
frag.appendChild(mark);
|
|
57
|
+
count += 1;
|
|
58
|
+
lastIndex = m.index + m[0].length;
|
|
59
|
+
}
|
|
60
|
+
if (lastIndex === 0) continue;
|
|
61
|
+
if (lastIndex < text.length) {
|
|
62
|
+
frag.appendChild(document.createTextNode(text.slice(lastIndex)));
|
|
63
|
+
}
|
|
64
|
+
textNode.parentNode.replaceChild(frag, textNode);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 无锚点时(intro / 仅标题命中)滚动到第一个匹配词,实现定位
|
|
68
|
+
if (!window.location.hash) {
|
|
69
|
+
var first = root.querySelector('mark.tag-plugin.mark[color="yellow"]');
|
|
70
|
+
if (first) {
|
|
71
|
+
var top = first.getBoundingClientRect().top + window.scrollY - 32;
|
|
72
|
+
window.scrollTo({ top: Math.max(0, top), behavior: 'instant' });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (document.readyState !== 'loading') {
|
|
78
|
+
highlightKeyword();
|
|
79
|
+
} else {
|
|
80
|
+
document.addEventListener('DOMContentLoaded', highlightKeyword);
|
|
81
|
+
}
|
|
82
|
+
})();
|