From 77b0f69d0c6e555349dd491d7ca209924d119e61 Mon Sep 17 00:00:00 2001 From: Matt Kosarek Date: Wed, 11 Mar 2026 17:49:05 -0400 Subject: Migrate to astro --- src/pages/posts/[slug].astro | 19 ++++++++++ src/pages/posts/feed.xml.ts | 21 +++++++++++ src/pages/posts/index.astro | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/pages/posts/[slug].astro create mode 100644 src/pages/posts/feed.xml.ts create mode 100644 src/pages/posts/index.astro (limited to 'src/pages/posts') diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro new file mode 100644 index 0000000..0f29ec5 --- /dev/null +++ b/src/pages/posts/[slug].astro @@ -0,0 +1,19 @@ +--- +import { getCollection, type CollectionEntry } from 'astro:content'; +import PostLayout from '../../layouts/PostLayout.astro'; + +export async function getStaticPaths() { + const posts = await getCollection('posts'); + return posts.map((post: CollectionEntry<'posts'>) => ({ + params: { slug: post.slug }, + props: { post }, + })); +} + +const { post } = Astro.props as { post: CollectionEntry<'posts'> }; +const { Content } = await post.render(); +--- + + + + diff --git a/src/pages/posts/feed.xml.ts b/src/pages/posts/feed.xml.ts new file mode 100644 index 0000000..43b9b84 --- /dev/null +++ b/src/pages/posts/feed.xml.ts @@ -0,0 +1,21 @@ +import rss from '@astrojs/rss'; +import { getCollection } from 'astro:content'; +import { marked } from 'marked'; +import type { APIContext } from 'astro'; + +export async function GET(context: APIContext) { + const posts = await getCollection('posts'); + posts.sort((a, b) => b.data.date.localeCompare(a.data.date)); + + return rss({ + title: "Matthew Kosarek's Blog", + description: 'Updates and thoughts from Matthew Kosarek', + site: context.site ?? 'https://matthewkosarek.xyz', + items: posts.map(post => ({ + title: post.data.title, + pubDate: new Date(post.data.date), + link: `/posts/${post.slug}/`, + content: marked(post.body) as string, + })), + }); +} diff --git a/src/pages/posts/index.astro b/src/pages/posts/index.astro new file mode 100644 index 0000000..b3ea740 --- /dev/null +++ b/src/pages/posts/index.astro @@ -0,0 +1,88 @@ +--- +import { getCollection, type CollectionEntry } from 'astro:content'; +import BaseLayout from '../../layouts/BaseLayout.astro'; +import '../../styles/post.css'; +import '../../styles/sitemap.css'; + +const allPosts = await getCollection('posts'); +allPosts.sort((a: CollectionEntry<'posts'>, b: CollectionEntry<'posts'>) => b.data.date.localeCompare(a.data.date)); + +function formatDate(dateStr: string): string { + const [year, month, day] = dateStr.split('-').map(Number); + const d = new Date(year, month - 1, day); + return d.toLocaleDateString('en-US', { month: 'long', day: '2-digit', year: 'numeric' }); +} +--- + + +
+

+ RSS Feed +
+ +
+ +
+
    + {allPosts.map((post: CollectionEntry<'posts'>) => ( +
  • +

    {post.data.title}

    +

    {formatDate(post.data.date)}

    +

    {post.data.tags.join(',')}

    +
  • + ))} +
+
+ + +
-- cgit v1.2.1