-
Notifications
You must be signed in to change notification settings - Fork 10
/
notes.astro
57 lines (56 loc) · 1.63 KB
/
notes.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
---
import Base from "@/layouts/BaseLayout.astro";
import FormattedDate, {
parseDateToString,
} from "@/components/FormattedDate.astro";
import { getCollection, type CollectionEntry } from "astro:content";
type NoteProps = CollectionEntry<"notes">;
const notes = await getCollection("notes");
const sortedNotes = notes.sort((a, b) => {
const aDate = a.data.published;
const bDate = b.data.published;
return Date.parse(bDate.toString()) - Date.parse(aDate.toString());
});
const groupedNotes = groupByDay(sortedNotes);
function groupByDay(items: NoteProps[]): Record<string, NoteProps[]> {
const grouped: Record<string, NoteProps[]> = {};
items.forEach((item) => {
const key = parseDateToString(item.data.published.toString());
if (!grouped[key]) {
grouped[key] = [];
}
grouped[key].push(item);
});
return grouped;
}
---
<Base>
<header class="relative mb-6 border-b-2 pb-2 pr-12">
<h1 class="font-bold">Notes</h1>
<p class="text-pretty text-secondary">Short-form thoughts and updates</p>
</header>
<main class="flex-grow">
<div class="prose">
<dl>
{
Object.entries(groupedNotes).map(([date, notes]) => {
return (
<>
<dt id={date}>
<FormattedDate date={new Date(date)} />
</dt>
{notes.map((note) =>
note.render().then(({ Content }) => (
<dd class="grid gap-y-2">
<Content />
</dd>
))
)}
</>
);
})
}
</dl>
</div>
</main>
</Base>