Skip to content

Commit 6ab007a

Browse files
committed
feat: 增加阅读体验增强与深色模式
- 新增 assets/css/style.scss:覆盖主题样式表(保留 @import 主题), 用 CSS 变量实现浅色/深色两套配色,含代码高亮深色 token 与打印适配 - 新增 assets/js/blog.js:阅读进度条、深色切换(含 localStorage 记忆)、 代码块一键复制、文章目录自动生成与滚动高亮、中英文混合阅读时长 - _layouts/post.html:新增阅读时长/分类元信息、目录容器、标签、 上一篇/下一篇导航 - _includes/head-custom.html:首屏前确定配色,避免深色模式白闪 - _layouts/default.html:引入 blog.js 全部为 Liquid/原生 JS 实现,未新增插件,兼容 GitHub Pages。
1 parent 3aa503c commit 6ab007a

5 files changed

Lines changed: 733 additions & 3 deletions

File tree

‎_includes/head-custom.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
{% comment %} 自定义 <head> 扩展:favicon 已在 default.html 引入,此处可放统计代码 / 自定义 meta {% endcomment %}
2+
<script>
3+
// 在首次绘制前确定配色,避免深色模式下的白屏闪烁
4+
(function () {
5+
var saved = null;
6+
try { saved = localStorage.getItem('theme'); } catch (e) { /* 隐私模式 */ }
7+
if (!saved && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
8+
saved = 'dark';
9+
}
10+
document.documentElement.setAttribute('data-theme', saved === 'dark' ? 'dark' : 'light');
11+
})();
12+
</script>

‎_layouts/default.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ <h1><a href="{{ "/" | absolute_url }}">{{ site.title | default: site.github.repo
6060
</footer>
6161
</div>
6262
<script src="{{ "/assets/js/scale.fix.js" | relative_url }}"></script>
63+
<script src="{{ "/assets/js/blog.js" | relative_url }}?v={{ site.time | date: "%s" }}"></script>
6364
</body>
6465
</html>

‎_layouts/post.html‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
---
22
layout: default
33
---
4-
<h1>{{ page.title }}</h1>
4+
<article class="post">
5+
<h1>{{ page.title }}</h1>
56

6-
<small>{{ page.date | date: "%Y年%-m月%-d日" }}</small>
7+
<p class="post-meta">
8+
<small>{{ page.date | date: "%Y年%-m月%-d日" }}</small>
9+
<span class="dot">·</span>
10+
<small data-reading-time>阅读时长计算中…</small>
11+
{% if page.categories and page.categories.size > 0 %}
12+
<span class="dot">·</span>
13+
<small>{% for c in page.categories %}{{ c }}{% unless forloop.last %} / {% endunless %}{% endfor %}</small>
14+
{% endif %}
15+
</p>
716

8-
{{ content }}
17+
<div id="toc" class="toc collapsed" hidden></div>
918

19+
{{ content }}
20+
21+
{% if page.tags and page.tags.size > 0 %}
22+
<p class="post-tags">
23+
{% for tag in page.tags %}
24+
<a href="{{ "/tags/" | relative_url }}#{{ tag | slugify }}">#{{ tag }}</a>
25+
{% endfor %}
26+
</p>
27+
{% endif %}
28+
29+
{% if page.previous or page.next %}
30+
<nav class="post-nav">
31+
{% if page.previous %}
32+
<a class="prev" href="{{ page.previous.url | relative_url }}">
33+
<span class="label">← 上一篇</span>{{ page.previous.title }}
34+
</a>
35+
{% endif %}
36+
{% if page.next %}
37+
<a class="next" href="{{ page.next.url | relative_url }}">
38+
<span class="label">下一篇 →</span>{{ page.next.title }}
39+
</a>
40+
{% endif %}
41+
</nav>
42+
{% endif %}
43+
</article>

0 commit comments

Comments
 (0)