feat(): Inferred types for blogs instead of static.

This commit is contained in:
kami
2026-03-04 04:51:58 +08:00
parent 7c8b1b8223
commit d3e3f50606
2 changed files with 20 additions and 8 deletions

View File

@@ -1,18 +1,25 @@
--- ---
import { getCollection, render } from 'astro:content'; import { getCollection, render } from 'astro:content';
import BlogPost from '@layouts/BlogPost.astro'; 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'); const posts = await getCollection('personal');
return posts.map(post => ({ return posts.map(post => ({
params: { id: post.id }, params: { id: post.id },
props: { post }, props: { post },
})); }));
} }) satisfies GetStaticPaths;
type Params = InferGetStaticParamsType<typeof getStaticPaths>;
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
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); const { Content } = await render(post);
--- ---

View File

@@ -1,16 +1,21 @@
--- ---
import { getCollection, render } from 'astro:content'; import { getCollection, render } from 'astro:content';
import BlogPost from '@layouts/BlogPost.astro'; 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'); const posts = await getCollection('uni');
return posts.map(post => ({ return posts.map(post => ({
params: { id: post.id }, params: { id: post.id },
props: { post }, props: { post },
})); }));
} }) satisfies GetStaticPaths;
type Params = InferGetStaticParamsType<typeof getStaticPaths>;
type Props = CollectionEntry<'blog'>; type Props = InferGetStaticPropsType<typeof getStaticPaths>;
const { post } = Astro.props; const { post } = Astro.props;
const { Content } = await render(post); const { Content } = await render(post);