summaryrefslogtreecommitdiff
path: root/src/pages/reading.astro
blob: 0e1d1cb132df965e0346ce454305fd6a3c80599b (plain)
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
---
import { getCollection, type CollectionEntry } from "astro:content";
import BaseLayout from "../layouts/BaseLayout.astro";
import ReadingEntry from "../components/ReadingEntry.astro";
import "../styles/post.css";
import "../styles/sitemap.css";

type ReadingYear = CollectionEntry<"reading">;
type Entry = ReadingYear["data"]["entries"][number];

const years = await getCollection("reading");
years.sort((a: ReadingYear, b: ReadingYear) => b.data.year - a.data.year);

// Entries are authored oldest-first within a year; show the most recent first.
function newestFirst(entries: Entry[]): Entry[] {
    return [...entries].reverse();
}
---

<BaseLayout
    title="Reading"
    description="Books and articles I've read/am reading"
>
    <div id="content" class="content">
        {
            years.map((year: ReadingYear) => {
                const entries = newestFirst(year.data.entries);
                const books = entries.filter((e: Entry) => e.type === "book");
                const articles = entries.filter(
                    (e: Entry) => e.type === "article",
                );

                return (
                    <section class="reading-year">
                        <h2>{year.data.year}</h2>

                        <div class="reading-year-body">
                            <ul class="org-ul">
                                {books.map((entry: Entry) => (
                                    <ReadingEntry entry={entry} />
                                ))}
                            </ul>

                            {articles.length > 0 && (
                                <Fragment>
                                    <h3 class="reading-subhead">Articles</h3>
                                    <ul class="org-ul">
                                        {articles.map((entry: Entry) => (
                                            <ReadingEntry entry={entry} />
                                        ))}
                                    </ul>
                                </Fragment>
                            )}
                        </div>
                    </section>
                );
            })
        }
    </div>
</BaseLayout>