-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.html
More file actions
69 lines (63 loc) · 2.56 KB
/
post.html
File metadata and controls
69 lines (63 loc) · 2.56 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>54chi</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="assets/css/site.css" />
</head>
<body>
<header>
<h1><a href="index.html">54chi</a></h1>
<nav><a href="about.html">About</a></nav>
</header>
<main>
<a class="back" href="index.html">← All posts</a>
<article id="post-content">Loading…</article>
</main>
<footer>
<p><a href="index.html">54chi</a></p>
</footer>
<!-- script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script-->
<script src="assets/js/marked.min.js"></script>
<script>
const slug = new URLSearchParams(window.location.search).get(
"slug",
);
const el = document.getElementById("post-content");
if (!slug) {
el.textContent = "No post specified.";
} else {
fetch("posts/" + slug + ".md")
.then(function (r) {
return r.ok ? r.text() : Promise.reject(r.status);
})
.then(function (text) {
// Strip and parse front matter
var fmMatch = text.match(
/^---\n([\s\S]*?)\n---\n\n?([\s\S]*)$/,
);
var body = fmMatch ? fmMatch[2] : text;
var fm = fmMatch ? fmMatch[1] : "";
var titleMatch = fm.match(/^title:\s*"?(.+?)"?\s*$/m);
var dateMatch = fm.match(/^date:\s*(.+?)\s*$/m);
var title = titleMatch ? titleMatch[1] : slug;
var date = dateMatch ? dateMatch[1] : "";
document.title = title + " | 54chi";
var header =
"<h1>" +
title +
"</h1>" +
(date
? '<p class="post-meta">' + date + "</p>"
: "");
el.innerHTML = header + marked.parse(body);
})
.catch(function () {
el.textContent = "Post not found.";
});
}
</script>
</body>
</html>