Update template to Astro 5.0, use Content Collections

This commit is contained in:
Cassidy Williams
2024-12-14 09:46:58 -06:00
parent 90a26b0085
commit 444cbe1502
16 changed files with 11018 additions and 9215 deletions

View File

@@ -1,4 +1,5 @@
---
import { getCollection } from "astro:content";
import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro";
@@ -7,11 +8,12 @@ import ColorScript from "../components/ColorScript.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
// Use Astro.glob() to fetch all posts, and then sort them by date.
const posts = (await Astro.glob("../posts/*.md")).sort(
let posts = await getCollection("posts");
posts = posts.sort(
(a, b) =>
new Date(b.frontmatter.updated || b.frontmatter.added).valueOf() -
new Date(a.frontmatter.updated || a.frontmatter.added).valueOf()
new Date(b.data.updated || b.data.added).valueOf() -
new Date(a.data.updated || a.data.added).valueOf(),
);
---
@@ -27,7 +29,7 @@ const posts = (await Astro.glob("../posts/*.md")).sort(
posts.map(
({
url,
frontmatter: { description, slug, title, tags, added: date },
data: { description, slug, title, tags, added: date },
}) => <Post {description} {date} {slug} {title} {tags} />
)
}