website/src/pages/api/blog/[slug].json.ts
2024-03-26 16:36:18 +01:00

27 lines
514 B
TypeScript

import { getCollection } from 'astro:content';
export async function GET({ params }: { params: { slug: string } }) {
const pages = await getCollection('blog');
return new Response(
JSON.stringify(pages.filter(post => {
return post.id.includes(params.slug)
})
))
}
export async function getStaticPaths() {
const pages = await getCollection('blog');
return pages.map(p => {
const [postId] = p.id.split('/');
return {
params: {
slug: postId
}
}
});
}