From 3947e069683ec0573ba3d032ed8bc473b3bc6e13 Mon Sep 17 00:00:00 2001 From: Graham Hall Date: Mon, 24 Jun 2024 21:32:27 -0400 Subject: [PATCH] switch to fully static site --- astro.config.mjs | 2 +- src/components/Tags.astro | 2 +- src/pages/archive/[tag].astro | 18 +++++++++++++++++- src/pages/index.astro | 3 +-- src/pages/posts/[...slug].astro | 1 - 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 7be3c38..2eed722 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,7 +8,7 @@ import mdx from '@astrojs/mdx'; // https://astro.build/config export default defineConfig({ site: 'https://ghall.blog', - output: 'hybrid', + output: 'static', adapter: netlify(), integrations: [ mdx(), diff --git a/src/components/Tags.astro b/src/components/Tags.astro index c1f0ecd..8a4ac8b 100644 --- a/src/components/Tags.astro +++ b/src/components/Tags.astro @@ -11,7 +11,7 @@ const { tags } = Astro.props;
{ tags.sort().map((tag: Tag) => ( - + #{tag} )) diff --git a/src/pages/archive/[tag].astro b/src/pages/archive/[tag].astro index 030e2fc..6816f03 100644 --- a/src/pages/archive/[tag].astro +++ b/src/pages/archive/[tag].astro @@ -4,7 +4,23 @@ import { getCollection } from 'astro:content'; import Layout from '@layouts/Layout.astro'; -export const prerender = false; +export async function getStaticPaths() { + const posts = await getCollection('blog'); + + const tags = ['all']; + posts.forEach((post) => + post.data.tags.forEach((tag) => { + if (!tags.includes(tag)) { + tags.push(tag); + } + }) + ); + + return tags.map((tag) => ({ + params: { tag }, + props: { tag }, + })); +} const { tag }: { tag?: string } = Astro.params; diff --git a/src/pages/index.astro b/src/pages/index.astro index 206cce1..560a63a 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,5 +1,4 @@ --- -export const prerender = true; import { getCollection } from 'astro:content'; import Layout from '@layouts/Layout.astro'; @@ -22,7 +21,7 @@ const posts = await getCollection('blog'); { posts.length < 6 ? null : ( ) } diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index bd76953..26f3a71 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -1,5 +1,4 @@ --- -export const prerender = true; import { getCollection } from 'astro:content'; import Layout from '@layouts/Layout.astro';