From df0c360155781bbd02fb42d17b13be19f594c9aa Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Thu, 19 Mar 2026 16:28:21 +0100 Subject: [PATCH] use native astro md rendering where possible --- src/pages/blog/[slug].astro | 17 ++++++++++------- src/pages/writing/[slug].astro | 16 ++++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/pages/blog/[slug].astro b/src/pages/blog/[slug].astro index d2384f3..9f55b75 100644 --- a/src/pages/blog/[slug].astro +++ b/src/pages/blog/[slug].astro @@ -1,12 +1,10 @@ --- -import {getCollection} from "astro:content"; +import {type CollectionEntry, getCollection} from "astro:content"; import BaseLayout from '../../layouts/BaseLayout.astro'; import Bio from '../../components/Bio.astro'; import readingTime from 'reading-time'; -import {marked} from 'marked'; export async function getStaticPaths() { - const posts = await getCollection('posts'); return posts.map(p => ({ params: { @@ -18,14 +16,17 @@ export async function getStaticPaths() { publishDate: p.data.publishDate, slug: p.slug, tags: p.data.tags, - content: marked.parse(p.body), readTime: readingTime(p.body).text, - } + }, })); } -const {slug, title, description, publishDate, tags, content, readTime} = Astro.props; +const {slug, title, description, publishDate, tags, readTime} = Astro.props; const permalink = `${Astro?.site?.href}blog/${slug}`; +const posts = await getCollection('posts'); +const entry: CollectionEntry<'posts'> | undefined = posts.find(e => e.slug === slug); +if (!entry) throw new Error(`Post not found: ${slug}`); +const { Content } = await entry.render(); --- @@ -40,7 +41,9 @@ const permalink = `${Astro?.site?.href}blog/${slug}`;
-
+
+ +

diff --git a/src/pages/writing/[slug].astro b/src/pages/writing/[slug].astro index 83bb41f..34f69ea 100644 --- a/src/pages/writing/[slug].astro +++ b/src/pages/writing/[slug].astro @@ -1,6 +1,5 @@ --- -import {getCollection} from "astro:content"; -import {marked} from 'marked'; +import {type CollectionEntry, getCollection} from "astro:content"; import BaseLayout from "../../layouts/BaseLayout.astro"; export async function getStaticPaths() { @@ -13,13 +12,16 @@ export async function getStaticPaths() { props: { title: p.data.title, slug: p.slug, - content: marked.parse(p.body), - } + }, })); } -const {slug, title, content} = Astro.props; +const {slug, title} = Astro.props; const permalink = `${Astro?.site?.href}writing/${slug}`; +const writing = await getCollection('writing'); +const entry: CollectionEntry<'writing'> | undefined = writing.find(e => e.slug === slug); +if (!entry) throw new Error(`Entry not found: ${slug}`); +const { Content } = await entry.render(); ---
@@ -27,7 +29,9 @@ const permalink = `${Astro?.site?.href}writing/${slug}`;
-
+
+ +