feat: some shit
This commit is contained in:
26
src/pages/api/blog/[slug].json.ts
Normal file
26
src/pages/api/blog/[slug].json.ts
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user