From cbdc98274ef5d671fdf8b3c532523feb02469399 Mon Sep 17 00:00:00 2001
From: Cory Dransfeldt <hi@coryd.dev>
Date: Sun, 17 Nov 2024 20:39:24 -0800
Subject: [PATCH] chore: static paths

---
 src/pages/books/years/[year].astro | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/pages/books/years/[year].astro b/src/pages/books/years/[year].astro
index e8c24f8..aa00cfb 100644
--- a/src/pages/books/years/[year].astro
+++ b/src/pages/books/years/[year].astro
@@ -13,6 +13,14 @@ import { DateTime } from "luxon";
 
 export const prerender = true;
 
+export async function getStaticPaths() {
+  const books = await fetchBooks();
+
+  return books.years.map((yearData) => ({
+    params: { year: String(yearData.value) },
+  }));
+}
+
 const { globals } = await fetchGlobalData(Astro);
 const books = await fetchBooks();
 const { year } = Astro.params;
@@ -45,7 +53,7 @@ const intro = isCurrentYear
   pageTitle={pageTitle}
   description={description}
   fullUrl={Astro.url.pathname}
-  ogImage={bookData[0].image}
+  ogImage={bookData[0]?.image || ""}
 >
   <a href="/books" class="back-link">
     <IconArrowLeft size={18} /> Back to books
@@ -53,10 +61,5 @@ const intro = isCurrentYear
   <h2 class="page-title">{year} / Books</h2>
   <div set:html={intro} />
   <hr />
-  <Grid
-    data={bookData}
-    shape="vertical"
-    count={200}
-    loading="eager"
-  />
+  <Grid data={bookData} shape="vertical" count={200} loading="eager" />
 </Layout>