-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy path[slug].tsx
More file actions
103 lines (96 loc) · 2.56 KB
/
[slug].tsx
File metadata and controls
103 lines (96 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
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
import { add, format, compareDesc, parseISO } from "date-fns";
import { FocusBoundary, Layout, Link } from "@components";
import {
loadAllMd,
loadMdBySlug,
processMd,
processMdPlaintext,
Transcript as TranscriptFrontmatter,
} from "@helpers/retrieveMdPages";
import { pick } from "@helpers/object";
export default function Transcript({
all,
title,
description,
date,
html,
}: Awaited<ReturnType<typeof getStaticProps>>["props"]) {
// A ridiculous method to ignore timezones
const formattedDate = format(add(parseISO(date), { days: 1 }), "EEEE PPP");
return (
<Layout
title={title}
sidebar
as={undefined}
description={`${title} | Q&A from ${date}
${description}`}
>
{(setSidebar: any) => (
<>
<h1>{title}</h1>
<FocusBoundary
onChange={setSidebar}
onEnter={undefined}
onExit={undefined}
>
<nav>
<ol>
{all.map((article) => (
<li key={article.slug}>
<Link
href={"/transcripts/" + article.slug}
title={article.title}
>
{article.title}
</Link>
</li>
))}
</ol>
</nav>
</FocusBoundary>
<div>
<p>
<em>Transcript from {formattedDate}</em>
</p>
<div
className="markdown"
dangerouslySetInnerHTML={{ __html: html }}
/>
</div>
</>
)}
</Layout>
);
}
export const getStaticProps = async ({
params,
}: {
params: { slug: string };
}) => {
const doc = await loadMdBySlug<TranscriptFrontmatter>(
"src/transcripts",
params.slug,
);
const transcripts = await loadAllMd<TranscriptFrontmatter>("src/transcripts");
const all = transcripts
.filter((x) => Boolean(x) && x.content !== "")
.map((x) => pick(["slug", "date", "title"], x))
.sort((a, b) =>
a.date && b.date ? compareDesc(parseISO(a.date), parseISO(b.date)) : 1,
);
return {
props: {
all,
...pick(["title", "date"], doc),
html: processMd(doc.content, { wrapFirstList: true }).html,
description: processMdPlaintext(doc.description).html,
},
};
};
export const getStaticPaths = async () => {
const transcripts = await loadAllMd<TranscriptFrontmatter>("src/transcripts");
return {
paths: transcripts.map(({ slug }) => ({ params: { slug } })),
fallback: false,
};
};