优化pjax刷新
This commit is contained in:
1 parent
86d2fb215a
commit
43d3e3a4f8
8 files changed
+65
-24
No files matched your search
@@ -49,12 +49,6 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: node scripts/optimize_images.js
|
||||
|
||||
- name: Fetch AI Greetings
|
||||
continue-on-error: true
|
||||
env:
|
||||
RSS_API_TOKEN: ${{ secrets.RSS_API_TOKEN }}
|
||||
run: node scripts/fetch_greetings.js
|
||||
|
||||
- name: Commit Optimized Images
|
||||
continue-on-error: true
|
||||
run: |
|
||||
|
||||
@@ -138,13 +138,13 @@ hasCJKLanguage = true
|
||||
# 搜索提示文案 (Search Hint Text)
|
||||
hint = "点击随笔 开始搜索"
|
||||
|
||||
# 时段问候语 (Time-based Greetings)
|
||||
# 时段问候语 (Time-based Greetings) - 数组格式,每次随机显示一条
|
||||
[params.home_search.greetings]
|
||||
morning = "早安!元气满满" # 6:00 - 11:00
|
||||
noon = "中午好!记得干饭" # 11:00 - 14:00
|
||||
afternoon = "下午好!喝杯茶吧" # 14:00 - 18:00
|
||||
evening = "晚上好!放松一下" # 18:00 - 22:00
|
||||
night = "早点睡对皮肤好" # 22:00 - 6:00
|
||||
morning = ["早安!元气满满", "新的一天,加油", "早起的鸟儿有虫吃"]
|
||||
noon = ["中午好!记得干饭", "午饭吃好了吗,来读篇博客", "午后适合摸鱼"]
|
||||
afternoon = ["下午好!喝杯茶吧", "下午茶时间到了", "下午适合发呆"]
|
||||
evening = ["晚上好!放松一下", "今晚月色不错", "夜深了,读篇好文"]
|
||||
night = ["早点睡对皮肤好", "夜猫子你好", "明天再看吧"]
|
||||
|
||||
# 节日问候语 (Holiday Greetings) - 格式: "MM-DD" = "文案"
|
||||
# 已包含 2026 年农历节日对应的公历日期
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
window.searchGreetings={"morning":"周末的早晨,适合赖床和码字","noon":"周末不用早起,但可以早起写博客","afternoon":"周末的早晨,适合赖床和码字","evening":"没有 deadline 的周末,写点想写的","night":"周末宅家,博客是最好的伴侣"};window.searchHolidays={};
|
||||
@@ -75,6 +75,8 @@
|
||||
if (content) linkify(content);
|
||||
}
|
||||
|
||||
window.initLinkify = run;
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', run);
|
||||
} else {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
})();
|
||||
@@ -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>
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user