mirror of
https://github.com/JuLi0n21/homepage.git
synced 2026-04-19 23:30:06 +00:00
feat(): Inferred types for blogs instead of static.
This commit is contained in:
@@ -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);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user