forked from LuaLS/LuaLS.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
[...slug].astro
82 lines (72 loc) · 2.17 KB
/
[...slug].astro
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
---
import { getCollection } from "astro:content";
import Layout from "~/layouts/WikiArticle.astro";
import CodeBlock from "~/components/common/CodeBlock.astro";
import WikiLink from "~/components/wiki/WikiLink.astro";
import type { CollectionEntry } from "astro:content";
import H1 from "~/components/wiki/headings/H1.astro";
import H2 from "~/components/wiki/headings/H2.astro";
import H3 from "~/components/wiki/headings/H3.astro";
import H4 from "~/components/wiki/headings/H4.astro";
import H5 from "~/components/wiki/headings/H5.astro";
import H6 from "~/components/wiki/headings/H6.astro";
import dayjs from "~/services/time";
import Tooltip from "~/components/common/Tooltip.astro";
export const getStaticPaths = async () => {
const articles = await getCollection("wiki");
return articles.map((article) => {
return { params: { slug: article.slug }, props: { article } };
});
};
const { article } = Astro.props;
const { Content, headings, remarkPluginFrontmatter } = await article.render();
export interface Props {
article: CollectionEntry<"wiki">;
}
const modifiedTime = remarkPluginFrontmatter.lastModified
? dayjs(remarkPluginFrontmatter.lastModified)
.utc()
.format("HH:mm:ss D MMMM, YYYY UTC")
: "Not committed yet";
---
<Layout article={article} headings={headings}>
<Content
components={{
pre: CodeBlock,
a: WikiLink,
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H6,
}}
/>
<div class="modified-timestamp">
<p>
Last Modified:
<Tooltip content={modifiedTime}>
<time datetime={remarkPluginFrontmatter.lastModified} data-localize
>{modifiedTime}</time
>
</Tooltip>
</p>
</div>
</Layout>
<script>
const times = document.querySelectorAll("time[data-localize]");
const formatter = new Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "2-digit",
day: "numeric",
month: "long",
year: "numeric",
second: "2-digit",
timeZoneName: "short",
});
times.forEach((el) => {
const timestamp = el.getAttribute("datetime");
if (!timestamp) return;
el.textContent = formatter.format(new Date(timestamp));
});
</script>