summaryrefslogtreecommitdiff
path: root/src/components/ReadingEntry.astro
blob: 3fa78603a557c09b1f9cba5116e0d6519e513254 (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
61
62
---
import type { CollectionEntry } from "astro:content";

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

interface Props {
    entry: Entry;
}

const { entry } = Astro.props;

const href =
    entry.url ??
    (entry.isbn ? `https://openlibrary.org/isbn/${entry.isbn}` : undefined);
const isReading = entry.status === "reading";
const statusLabel = isReading ? "Currently reading" : "Finished";
---

<li>
    <p>
        <span
            class:list={[
                "reading-status",
                isReading ? "reading-status--reading" : "reading-status--done",
            ]}
            role="img"
            aria-label={statusLabel}
            title={statusLabel}
        >
            {
                !isReading && (
                    <svg viewBox="0 0 16 16" aria-hidden="true">
                        <path d="M3.6 8.4 6.4 11.2 12.4 4.8" />
                    </svg>
                )
            }
        </span>
        {
            href ? (
                <a href={href} target="_blank" rel="noopener noreferrer">{entry.title}</a>
            ) : (
                <span class="reading-title">{entry.title}</span>
            )
        }
        {entry.author && <span class="reading-author">by {entry.author}</span>}
    </p>
    {entry.note && <div class="reading-note">{entry.note}</div>}
    {
        entry.isbn && (
            <div class="reading-isbn">
                <a
                    href={`https://openlibrary.org/isbn/${entry.isbn}`}
                    target="_blank"
                    rel="noopener noreferrer"
                >
                    ISBN {entry.isbn}
                </a>
            </div>
        )
    }
</li>