From d3e3f5060652bec71d5e91f871018865441181cf Mon Sep 17 00:00:00 2001 From: kami <97310758+VlxtIykg@users.noreply.github.com> Date: Wed, 4 Mar 2026 04:51:58 +0800 Subject: [PATCH] feat(): Inferred types for blogs instead of static. --- src/pages/blog/personal/[id].astro | 15 +++++++++++---- src/pages/blog/university/[id].astro | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/pages/blog/personal/[id].astro b/src/pages/blog/personal/[id].astro index e2a6222..b7af1a2 100644 --- a/src/pages/blog/personal/[id].astro +++ b/src/pages/blog/personal/[id].astro @@ -1,18 +1,25 @@ --- import { getCollection, render } from 'astro:content'; import BlogPost from '@layouts/BlogPost.astro'; +import type { + InferGetStaticParamsType, + InferGetStaticPropsType, + GetStaticPaths, +} from "astro"; -export async function getStaticPaths() { +export const getStaticPaths = (async () => { const posts = await getCollection('personal'); return posts.map(post => ({ params: { id: post.id }, props: { post }, })); -} +}) satisfies GetStaticPaths; +type Params = InferGetStaticParamsType; +type Props = InferGetStaticPropsType; -type Props = CollectionEntry<'blog'>; -const { post } = Astro.props; +const { post } = Astro.props as Props; +const { id } = Astro.params as Params; const { Content } = await render(post); --- diff --git a/src/pages/blog/university/[id].astro b/src/pages/blog/university/[id].astro index 24b3c90..681fbd6 100644 --- a/src/pages/blog/university/[id].astro +++ b/src/pages/blog/university/[id].astro @@ -1,16 +1,21 @@ --- import { getCollection, render } from 'astro:content'; import BlogPost from '@layouts/BlogPost.astro'; +import type { + InferGetStaticParamsType, + InferGetStaticPropsType, + GetStaticPaths, +} from "astro"; -export async function getStaticPaths() { +export const getStaticPaths = (async () => { const posts = await getCollection('uni'); return posts.map(post => ({ params: { id: post.id }, props: { post }, })); -} - -type Props = CollectionEntry<'blog'>; +}) satisfies GetStaticPaths; +type Params = InferGetStaticParamsType; +type Props = InferGetStaticPropsType; const { post } = Astro.props; const { Content } = await render(post);