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
      }
    }
  });
}
