-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.tsx
60 lines (57 loc) · 1.63 KB
/
tag.tsx
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
/** @jsx Nano.h */
/** @jsxFrag Nano.Fragment */
import * as Nano from "nano";
import site from "site";
import { relative } from "std/path/mod.ts";
import { Data, sort, url } from "meta";
import { BreadcrumbList } from "components/breadcrumb-list.tsx";
export default function* (): Generator<Data> {
const tags = new Set(
site.pages.map((page) => page.data.tags).flat().filter(Boolean)
.map((tag) => tag!.toLowerCase()),
);
for (const tag of tags) {
const title = `#${tag}`;
const sourceFile = relative(site.src(), new URL(import.meta.url).pathname);
yield {
url: url.tag(tag),
title,
tag,
layout: "layouts/base.tsx",
type: "tag",
sourceFile,
content: () => (
<>
<h1 class="heading">{title}</h1>
<BreadcrumbList
items={[{
name: "tags",
url: site.url(
relative(
site.src(),
new URL("./tags.tsx", import.meta.url).pathname,
),
),
}, { name: title, url: url.tag(tag) }]}
/>
<main class="my-5">
<ol>
{site.pages
.filter((page) => page.data.tags?.includes(tag))
.sort(sort.pages.dateDescending)
.map(
(page) => (
<li class="list-disc">
<a href={site.url(page.data.url as string)}>
{page.data.title}
</a>
</li>
),
)}
</ol>
</main>
</>
),
};
}
}