优化pjax刷新

This commit is contained in:
Vaica committed 2026-06-02 14:34:23 +08:00
1 parent cc5887a74d
commit cda4dbb24b
8 files changed
+65 -24

No files matched your search

+2
View File
@@ -75,6 +75,8 @@
if (content) linkify(content);
}
window.initLinkify = run;
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', run);
} else {
+7
View File
@@ -171,5 +171,12 @@ document.addEventListener("pjax:complete", function () {
} catch(e) { console.error('initImageFrameReveal error:', e); }
}
// 重载文章动画
if (typeof window.initPostScrollspy === 'function') window.initPostScrollspy();
// 重载链接卡片
if (typeof window.initLinkify === 'function') window.initLinkify();
// 重载中英文间距
if (typeof window.initPangu === 'function') window.initPangu();
refreshHeatmap();
});
+43
View File
@@ -0,0 +1,43 @@
// pangu.js - Auto insert spaces between CJK and half-width characters
(function() {
// CJK Unified Ideographs + common ranges
var CJK = '⺀-⻿⼀-⿟぀-ゟ゠-ヿ㄀-ㄯ㈀-㋿㐀-䶿一-鿿豈-﫿︰-﹏＀-￯';
var CJK_RE = new RegExp('([' + CJK + '])', 'g');
// Insert space between CJK and half-width (letters, digits, symbols)
function panguText(text) {
// CJK followed by half-width
text = text.replace(new RegExp('([' + CJK + '])([a-zA-Z0-9@#$%&=+<>|\\\\])', 'g'), '$1 $2');
// Half-width followed by CJK
text = text.replace(new RegExp('([a-zA-Z0-9@#$%&=+<>|\\\\])([' + CJK + '])', 'g'), '$1 $2');
return text;
}
function panguNode(root) {
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
var nodes = [];
while (walker.nextNode()) {
var node = walker.currentNode;
// Skip code, pre, script, style, input
if (node.parentElement && node.parentElement.closest('code, pre, script, style, input, textarea')) continue;
if (node.textContent.length > 1) nodes.push(node);
}
nodes.forEach(function(node) {
var spaced = panguText(node.textContent);
if (spaced !== node.textContent) node.textContent = spaced;
});
}
function run() {
var content = document.querySelector('.post-content');
if (content) panguNode(content);
}
window.initPangu = run;
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', run);
} else {
run();
}
})();
+5 -6
View File
@@ -25,18 +25,17 @@
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function initPostScrollspy() {
var content = document.getElementById('post-writing');
if (!content) return;
// 滚动时内容从下方淡入,符合"往下看"的直觉
content.querySelectorAll('h2, h3, h4, p, ul, ol, blockquote, table').forEach(function(el) {
el.setAttribute('uk-scrollspy', 'cls: uk-animation-fade; delay: 60');
if (!el.hasAttribute('uk-scrollspy')) el.setAttribute('uk-scrollspy', 'cls: uk-animation-fade; delay: 60');
});
// 图片/视频/链接卡片稍微带点位移,更有"出现感"
content.querySelectorAll('figure, img, .post-video, .link-card').forEach(function(el) {
el.setAttribute('uk-scrollspy', 'cls: uk-animation-slide-bottom-small; delay: 100');
if (!el.hasAttribute('uk-scrollspy')) el.setAttribute('uk-scrollspy', 'cls: uk-animation-slide-bottom-small; delay: 100');
});
});
}
document.addEventListener('DOMContentLoaded', initPostScrollspy);
</script>
+2 -5
View File
@@ -68,13 +68,10 @@
{{ $artalkModule := resources.Get "js/modules/artalk.js" }}
{{ $pjaxLib := resources.Get "js/libs/pjax.js" }}
{{ $linkify := resources.Get "js/modules/linkify.js" }}
{{ $pangu := resources.Get "js/modules/pangu.js" }}
{{ $scripts := slice $iconfont $uikit $easylazyload $viewimage $utils $loader $cache $search $floatingTools $paragraphComments $infiniteScroll $artalkModule $nprogress $pjaxLib $linkify $main $mypjax $toast $tiaozhuan $reward | resources.Concat "js/bundle.js" | resources.Minify | resources.Fingerprint }}
{{ $scripts := slice $iconfont $uikit $easylazyload $viewimage $utils $loader $cache $search $floatingTools $paragraphComments $infiniteScroll $artalkModule $nprogress $pjaxLib $pangu $linkify $main $mypjax $toast $tiaozhuan $reward | resources.Concat "js/bundle.js" | resources.Minify | resources.Fingerprint }}
{{ $aiGreetings := "static/js/ai_greetings.js" }}
{{ if os.FileExists $aiGreetings }}
<script defer src="/js/ai_greetings.js"></script>
{{ end }}
<script>
window.enableInfiniteScroll = {{ .Site.Params.infiniteScroll.enable | default false }};
</script>