-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.html
More file actions
executable file
·256 lines (225 loc) · 11 KB
/
Copy pathpost.html
File metadata and controls
executable file
·256 lines (225 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Loading… — Luv(sic) Notes</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Lora:ital,wght@0,400..700;1,400..700&display=swap" rel="stylesheet" />
<!-- 中文字体:思源宋体 + 思源黑体(Google Fonts 按字重分包) -->
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;600;700&display=swap" rel="stylesheet" />
<!-- 中文字体:霞鹜文楷 屏幕阅读版(jsDelivr 分包 CDN,按需加载) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-screen-web/style.css" />
<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" />
<!-- Highlight.js 双主题 -->
<link id="hljs-light" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/atom-one-light.min.css" />
<link id="hljs-dark" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/atom-one-dark.min.css" disabled />
<link rel="stylesheet" href="assets/styles.css" />
<script>
(function () {
var theme;
try { theme = localStorage.getItem('luvsic-theme'); } catch (_) {}
if (theme !== 'light' && theme !== 'dark') {
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark' : 'light';
}
document.documentElement.setAttribute('data-theme', theme);
var hljsLight = document.getElementById('hljs-light');
var hljsDark = document.getElementById('hljs-dark');
if (hljsLight) hljsLight.disabled = (theme !== 'light');
if (hljsDark) hljsDark.disabled = (theme !== 'dark');
})();
</script>
</head>
<body>
<div class="site-shell">
<header class="topbar" id="site-topbar"></header>
<div class="post-layout" id="post-layout">
<div class="article-col">
<article class="article-shell" id="article-shell">
<div class="loading-state">Loading note…</div>
</article>
<nav class="post-nav" id="post-nav" aria-label="Adjacent notes"></nav>
</div>
<aside class="toc-sidebar" id="toc-sidebar">
<div class="toc-title">目录</div>
<ul class="toc-list" id="toc-list"></ul>
</aside>
</div>
<footer class="site-footer" id="site-footer"></footer>
</div>
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.2.4/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/javascript.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/python.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/bash.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/css.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/plaintext.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/cpp.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/markdown.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/yaml.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/languages/cmake.min.js"></script>
<script src="assets/app.js"></script>
<script>
(async function () {
const $ = (s) => document.querySelector(s);
const { escapeHtml, formatDate, slugify } = LuvsicBlog;
const params = new URLSearchParams(location.search);
const slug = params.get("slug");
try {
const [config, postsIndex] = await Promise.all([
LuvsicBlog.loadConfig(),
LuvsicBlog.loadPostsIndex()
]);
// Theme
LuvsicBlog.applyTheme(
LuvsicBlog.resolveInitialTheme((config.defaults && config.defaults.theme) || "auto")
);
LuvsicBlog.renderTopbar("#site-topbar", config);
LuvsicBlog.renderFooter("#site-footer", config);
const posts = postsIndex.posts;
const idx = posts.findIndex((p) => p.slug === slug);
if (idx === -1) {
throw new Error(`Note not found: ${slug}`);
}
const post = posts[idx];
// title
document.title = `${post.title} — ${config.site.title}`;
// build a title-slug map so wiki-links can resolve to real posts
const postsBySlugifiedTitle = {};
posts.forEach((p) => { postsBySlugifiedTitle[slugify(p.title)] = p.slug; });
// fetch markdown
const mdText = await LuvsicBlog.loadText(`posts/${post.file}`);
const { data: fm, body } = LuvsicBlog.parseFrontmatter(mdText);
// merge metadata: frontmatter wins for display title if present
const displayTitle = fm.title || post.title;
const displayDate = fm.date || post.date;
const cat = (config.categories || []).find((c) => c.id === post.category);
// render article head
const tags = (fm.tags && Array.isArray(fm.tags) ? fm.tags : (post.tags || []))
.map((t) => `<span class="tag-chip">#${escapeHtml(t)}</span>`).join("");
const accentClass = cat && cat.accent === "amber" ? "accent-amber" : "";
$("#article-shell").innerHTML = `
<header class="article-head">
<div class="article-meta">
<span class="category-chip ${accentClass}">${escapeHtml(cat ? cat.name : post.category || "Note")}</span>
<span class="dot" aria-hidden="true"></span>
<time datetime="${escapeHtml(displayDate)}">${formatDate(displayDate)}</time>
${post.readingTime ? `<span class="dot" aria-hidden="true"></span><span>${escapeHtml(String(post.readingTime))} min read</span>` : ""}
</div>
<h1>${escapeHtml(displayTitle)}</h1>
${tags ? `<div class="article-tags">${tags}</div>` : ""}
</header>
<div class="prose" id="prose-body"></div>
`;
// render markdown → HTML
const html = LuvsicBlog.renderMarkdown(body, { postsBySlugifiedTitle });
$("#prose-body").innerHTML = html;
// enhance (highlight + KaTeX + copy bindings)
LuvsicBlog.enhanceRenderedContent($("#article-shell"));
// Build TOC from prose headings
(function buildTOC() {
const prose = $("#prose-body");
if (!prose) return;
const hTags = prose.querySelectorAll("h1, h2, h3");
if (hTags.length < 1) { $("#toc-sidebar").style.display = "none"; return; }
const tocList = $("#toc-list");
const tocData = [];
hTags.forEach((el) => {
const id = el.id;
const text = el.textContent.trim();
if (!id || !text) return;
const tag = el.tagName;
const li = document.createElement("li");
let levelClass = "";
if (tag === "H2") levelClass = "toc-h2";
else if (tag === "H3") levelClass = "toc-h3";
li.className = "toc-item" + (levelClass ? " " + levelClass : "");
const a = document.createElement("a");
a.href = "#" + id;
a.textContent = text;
a.addEventListener("click", function (e) {
const target = document.getElementById(id);
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: "smooth", block: "start" });
history.replaceState(null, "", "#" + id);
}
});
li.appendChild(a);
tocList.appendChild(li);
tocData.push({ el, id });
});
function updateActive() {
const scrollY = window.scrollY + 120;
let current = null;
for (let i = 0; i < tocData.length; i++) {
if (tocData[i].el.offsetTop <= scrollY) {
current = tocData[i];
} else {
break;
}
}
tocList.querySelectorAll(".toc-item").forEach(function (it) {
it.classList.remove("active");
});
if (current) {
var activeLi = tocList.querySelector('a[href="#' + current.id + '"]');
if (activeLi && activeLi.parentElement) {
activeLi.parentElement.classList.add("active");
}
}
}
var ticking = false;
window.addEventListener("scroll", function () {
if (!ticking) {
requestAnimationFrame(function () {
updateActive();
ticking = false;
});
ticking = true;
}
}, { passive: true });
updateActive();
})();
// prev / next nav
const prev = posts[idx + 1]; // older
const next = posts[idx - 1]; // newer
const prevHtml = prev
? `<a href="post.html?slug=${encodeURIComponent(prev.slug)}">
<span class="nav-label">← Older</span>
<span class="nav-title">${escapeHtml(prev.title)}</span>
</a>`
: `<div class="placeholder"></div>`;
const nextHtml = next
? `<a class="next-post" href="post.html?slug=${encodeURIComponent(next.slug)}">
<span class="nav-label">Newer →</span>
<span class="nav-title">${escapeHtml(next.title)}</span>
</a>`
: `<div class="placeholder"></div>`;
$("#post-nav").innerHTML = prevHtml + nextHtml;
} catch (err) {
console.error(err);
$("#article-shell").innerHTML = `
<div class="error-state">
<p style="font-size:1.1rem; margin-bottom:10px;">Could not load this note.</p>
<p style="font-size:0.92rem;">
${escapeHtml(err.message || "Unknown error")}<br />
Make sure you're serving via HTTP (e.g. <code>python3 -m http.server</code>)
and that <code>posts/index.json</code> contains a matching <code>slug</code>.
</p>
<p style="margin-top:14px;"><a href="index.html">← Back to notes</a></p>
</div>
`;
}
})();
</script>
</body>
</html>