Dane's personal website dane.computer

update blog index page

nulfrost 948c63b4 df76a68f

+29 -15
+6 -6
src/components/BlogPost.astro
··· 1 1 --- 2 2 interface Props { 3 - title: string; 4 - published_at: Date; 5 - slug: string; 3 + title: string; 4 + publishedAt: string; 5 + slug: string; 6 6 } 7 7 8 - const { title, published_at, slug } = Astro.props; 8 + const { title, publishedAt, slug } = Astro.props; 9 9 import Link from "@components/Link.astro"; 10 10 --- 11 11 ··· 17 17 <Link href={`/blogs/${slug}`}>{title}</Link> 18 18 </h2> 19 19 <footer class="text-sm text-gray-500"> 20 - <time datetime={published_at.toISOString()}> 20 + <time datetime={publishedAt}> 21 21 { 22 22 new Intl.DateTimeFormat("en-us", { 23 23 dateStyle: "medium", 24 - }).format(new Date(published_at)) 24 + }).format(new Date(publishedAt)) 25 25 } 26 26 </time> 27 27 </footer>
+13 -2
src/content.config.ts
··· 1 - import { defineCollection } from "astro:content"; 1 + import { defineCollection, z } from "astro:content"; 2 2 import { leafletStaticLoader } from "@nulfrost/leaflet-loader-astro"; 3 + import { glob } from "astro/loaders"; 4 + 5 + const blogs = defineCollection({ 6 + loader: glob({ pattern: "**/*.mdx", base: "./src/data/blog" }), 7 + schema: z.object({ 8 + title: z.string(), 9 + description: z.string(), 10 + year: z.number(), 11 + published_at: z.date(), 12 + }), 13 + }); 3 14 4 15 const documents = defineCollection({ 5 16 loader: leafletStaticLoader({ repo: "did:plc:qttsv4e7pu2jl3ilanfgc3zn" }), 6 17 }); 7 18 8 - export const collections = { documents }; 19 + export const collections = { documents, blogs };
+9 -7
src/pages/blogs/index.astro
··· 3 3 import BlogPost from "@components/BlogPost.astro"; 4 4 import { getCollection } from "astro:content"; 5 5 6 - const posts = (await getCollection("blog")).sort( 7 - (a, b) => b.data.published_at.valueOf() - a.data.published_at.valueOf(), 8 - ); 6 + // const posts = (await getCollection("blogs")).sort( 7 + // (a, b) => b.data.published_at.valueOf() - a.data.published_at.valueOf(), 8 + // ); 9 + 10 + const documents = await getCollection("documents"); 9 11 --- 10 12 11 13 <Layout ··· 15 17 <h1 class="mt-4 mb-4 text-2xl font-bold text-snes-black">Blog</h1> 16 18 <ul class="space-y-4"> 17 19 { 18 - posts.map((post) => ( 20 + documents.map((document) => ( 19 21 <BlogPost 20 - title={post.data.title} 21 - slug={post.id} 22 - published_at={post.data.published_at} 22 + title={document.data.title} 23 + slug={document.id} 24 + publishedAt={document.data.publishedAt} 23 25 /> 24 26 )) 25 27 }
+1
src/pages/index.astro
··· 5 5 6 6 import { getCollection } from "astro:content"; 7 7 const documents = await getCollection("documents"); 8 + const blogs = await getCollection("blogs"); 8 9 --- 9 10 10 11 <Layout