Skip to content

Commit 282c27c

Browse files
committed
feat: 让博客像老朋友——问候、记忆、指路、彩蛋
一次「有温度」的体验升级,全部纯原生、可离线: 1. 首页时间问候 + 博客年龄 - 按访问时段显示「早上好☀️/晚上好🌙」等问候 - 显示博客从首篇文章算起的「年龄」,精确到月(刚起步更有成长感) 2. 文章阅读进度记忆 - 记住每篇文章的滚动位置,下次回来弹出「回到上次位置」 3. 文章底部「相关阅读」 - 按共同标签自动推荐,排除当前文章 4. 404 彩蛋页 - ASCII 大「404」+ 随机台词 +「随便带我去哪」随机跳转 5. Konami 代码彩蛋 - ↑↑↓↓←→←→BA 触发隐藏成就弹窗 6. 终端新增 joke 命令 - 程序员冷笑话,help 与 Tab 补全同步 新增 assets/js/extra.js,统一承载问候/进度记忆/Konami 三个能力。
1 parent d6ec17c commit 282c27c

7 files changed

Lines changed: 453 additions & 8 deletions

File tree

‎404.md‎

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,73 @@
11
---
22
title: 404 - 页面未找到
3-
permalink: /404.html # 固定路径,GitHub Pages自动识别
3+
permalink: /404.html
44
---
5-
## 😕 抱歉,你访问的页面不存在
6-
- 可能是网址输入错误
7-
- 点击<a href="{{ site.url | relative_url }}">返回首页</a>
5+
6+
<div class="notfound">
7+
<pre class="notfound-ascii" aria-hidden="true">
8+
.----------------. .----------------. .----------------.
9+
| .--------------. || .--------------. || .--------------. |
10+
| | ___ ___ | || | ____ | || | _____ | |
11+
| | / _ \/ _ \ | || | / __ \ | || | |_ _| | |
12+
| | | | | | | | | || | / / \ \ | || | | | | |
13+
| | | | | | | | | || | | | | | | || | | | | |
14+
| | | |_| | |_| | || | | | | | | || | _| |_ | |
15+
| | |____/ \___/ | || | \ \__/ / | || | |_____| | |
16+
| | | || | \____/ | || | | |
17+
| '--------------' || '--------------' || '--------------' |
18+
'----------------' '----------------' '----------------'
19+
</pre>
20+
21+
<h2 id="nf-title">😕 咦,这里什么都没有</h2>
22+
<p id="nf-message" class="page-desc">加载中……</p>
23+
24+
<div class="hero-actions" style="margin-top:16px">
25+
<a class="hero-btn hero-btn-primary" href="{{ "/" | relative_url }}">回首页</a>
26+
<button class="hero-btn" id="nf-random" type="button">🎲 随便带我去哪</button>
27+
</div>
28+
</div>
29+
30+
<script type="application/json" id="nf-data">
31+
{
32+
"home": {{ "/" | relative_url | jsonify }},
33+
"posts": [
34+
{%- for post in site.posts -%}
35+
{{ post.url | relative_url | jsonify }}{%- unless forloop.last -%},{%- endunless -%}
36+
{%- endfor -%}
37+
]
38+
}
39+
</script>
40+
41+
<script>
42+
(function () {
43+
'use strict';
44+
45+
var lines = [
46+
'你走进了一间空荡荡的房间。这里曾经有一篇文章,也可能从未有过。',
47+
'这个页面 404 了。它可能去度假了,也可能本来就不存在。',
48+
'你来到了博客的边界之外。地图在这里画到了尽头。',
49+
'服务器说:没有。浏览器说:真的没有。你说:那我自己逛逛。',
50+
'这个地址像一条被删除的提交,永远留在了历史里。',
51+
'也许你手滑多打了一个字母,也许宇宙在这里开了个玩笑。'
52+
];
53+
54+
var dataEl = document.getElementById('nf-data');
55+
var msg = document.getElementById('nf-message');
56+
var randBtn = document.getElementById('nf-random');
57+
58+
var posts = [];
59+
if (dataEl) {
60+
try { posts = JSON.parse(dataEl.textContent).posts || []; } catch (e) { posts = []; }
61+
}
62+
63+
msg.textContent = lines[Math.floor(Math.random() * lines.length)];
64+
65+
if (randBtn && posts.length) {
66+
randBtn.addEventListener('click', function () {
67+
window.location.href = posts[Math.floor(Math.random() * posts.length)];
68+
});
69+
} else if (randBtn) {
70+
randBtn.hidden = true;
71+
}
72+
})();
73+
</script>

‎_layouts/default.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ <h1><a href="{{ "/" | absolute_url }}">{{ site.title | default: site.github.repo
7373
</div>
7474
<script src="{{ "/assets/js/scale.fix.js" | relative_url }}"></script>
7575
<script src="{{ "/assets/js/blog.js" | relative_url }}?v={{ site.time | date: "%s" }}"></script>
76+
<script src="{{ "/assets/js/extra.js" | relative_url }}?v={{ site.time | date: "%s" }}"></script>
7677
</body>
7778
</html>

‎_layouts/post.html‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
layout: default
33
---
44
<article class="post">
5+
<div id="resume-reading" class="resume-reading" hidden>
6+
<span class="resume-label">继续阅读</span>
7+
<button class="resume-jump" type="button">回到上次位置</button>
8+
<button class="resume-close" type="button" aria-label="关闭">×</button>
9+
</div>
10+
511
<h1>{{ page.title }}</h1>
612

713
<p class="post-meta">
@@ -40,4 +46,26 @@ <h1>{{ page.title }}</h1>
4046
{% endif %}
4147
</nav>
4248
{% endif %}
49+
50+
{% if page.tags and page.tags.size > 0 %}
51+
{% assign related_posts = "" | split: "" %}
52+
{% for tag in page.tags %}
53+
{% for p in site.tags[tag] %}
54+
{% unless p.url == page.url %}
55+
{% assign related_posts = related_posts | push: p %}
56+
{% endunless %}
57+
{% endfor %}
58+
{% endfor %}
59+
{% assign related_posts = related_posts | uniq %}
60+
{% if related_posts.size > 0 %}
61+
<div class="related-posts">
62+
<h2>相关阅读</h2>
63+
<ul>
64+
{% for p in related_posts limit: 4 %}
65+
<li><a href="{{ p.url | relative_url }}">{{ p.title }}</a></li>
66+
{% endfor %}
67+
</ul>
68+
</div>
69+
{% endif %}
70+
{% endif %}
4371
</article>

‎assets/css/style.scss‎

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,160 @@ kbd {
899899
color: var(--text);
900900
}
901901

902+
/* ==========================================================================
903+
404 彩蛋页
904+
========================================================================== */
905+
.notfound {
906+
text-align: center;
907+
padding: 10px 0 20px;
908+
}
909+
910+
.notfound-ascii {
911+
display: inline-block;
912+
margin: 0 auto 16px;
913+
text-align: left;
914+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
915+
font-size: 11px;
916+
line-height: 1.3;
917+
color: var(--heading);
918+
overflow-x: auto;
919+
max-width: 100%;
920+
}
921+
922+
.notfound h2 {
923+
margin: 0 0 10px;
924+
}
925+
926+
/* ==========================================================================
927+
继续阅读浮层
928+
========================================================================== */
929+
.resume-reading {
930+
display: flex;
931+
align-items: center;
932+
gap: 10px;
933+
padding: 10px 14px;
934+
margin-bottom: 16px;
935+
background: var(--panel);
936+
border: 1px solid var(--border);
937+
border-left: 3px solid var(--link);
938+
border-radius: 6px;
939+
}
940+
941+
.resume-label {
942+
font-size: 13px;
943+
color: var(--text);
944+
}
945+
946+
.resume-jump {
947+
padding: 5px 12px;
948+
font-family: inherit;
949+
font-size: 13px;
950+
color: #ffffff;
951+
background: var(--link);
952+
border: 0;
953+
border-radius: 5px;
954+
cursor: pointer;
955+
}
956+
957+
.resume-jump:hover { background: var(--link-hover); }
958+
959+
.resume-close {
960+
margin-left: auto;
961+
padding: 0 6px;
962+
font-size: 18px;
963+
line-height: 1;
964+
color: var(--muted);
965+
background: transparent;
966+
border: 0;
967+
cursor: pointer;
968+
}
969+
970+
.resume-close:hover { color: var(--heading); }
971+
972+
/* ==========================================================================
973+
文章底部相关阅读
974+
========================================================================== */
975+
.related-posts {
976+
margin-top: 28px;
977+
padding-top: 16px;
978+
border-top: 1px solid var(--border);
979+
}
980+
981+
.related-posts h2 {
982+
margin: 0 0 12px;
983+
font-size: 16px;
984+
}
985+
986+
.related-posts ul {
987+
margin: 0;
988+
padding-left: 0;
989+
list-style: none;
990+
}
991+
992+
.related-posts li {
993+
margin: 0 0 8px;
994+
font-size: 14px;
995+
}
996+
997+
.related-posts a { text-decoration: none; }
998+
.related-posts a:hover { text-decoration: underline; }
999+
1000+
/* ==========================================================================
1001+
Konami 彩蛋弹窗
1002+
========================================================================== */
1003+
.konami-overlay {
1004+
position: fixed;
1005+
inset: 0;
1006+
z-index: 9999;
1007+
display: flex;
1008+
align-items: center;
1009+
justify-content: center;
1010+
background: rgba(0, 0, 0, .6);
1011+
padding: 20px;
1012+
}
1013+
1014+
.konami-box {
1015+
max-width: 420px;
1016+
padding: 28px 26px;
1017+
text-align: center;
1018+
background: var(--bg);
1019+
border: 1px solid var(--border);
1020+
border-radius: 12px;
1021+
box-shadow: 0 12px 40px var(--shadow);
1022+
}
1023+
1024+
.konami-emoji {
1025+
font-size: 44px;
1026+
line-height: 1;
1027+
margin-bottom: 12px;
1028+
}
1029+
1030+
.konami-text {
1031+
margin: 0 0 8px;
1032+
font-size: 16px;
1033+
font-weight: 700;
1034+
color: var(--heading);
1035+
}
1036+
1037+
.konami-sub {
1038+
margin: 0 0 20px;
1039+
font-size: 14px;
1040+
color: var(--text);
1041+
}
1042+
1043+
.konami-close {
1044+
padding: 8px 16px;
1045+
font-family: inherit;
1046+
font-size: 14px;
1047+
color: #ffffff;
1048+
background: var(--link);
1049+
border: 0;
1050+
border-radius: 6px;
1051+
cursor: pointer;
1052+
}
1053+
1054+
.konami-close:hover { background: var(--link-hover); }
1055+
9021056
/* ==========================================================================
9031057
打印
9041058
========================================================================== */
@@ -910,7 +1064,9 @@ kbd {
9101064
.post-nav,
9111065
.search-box,
9121066
.hero-actions,
913-
.terminal { display: none !important; }
1067+
.terminal,
1068+
.resume-reading,
1069+
.konami-overlay { display: none !important; }
9141070

9151071
:root,
9161072
[data-theme="dark"] {

0 commit comments

Comments
 (0)