import { getLLMText, source } from '@/lib/source';
import { notFound } from 'next/navigation';

type MarkdownRouteProps = {
  params: Promise<{
    slug?: string[];
  }>;
};

export const revalidate = false;

export async function GET(_request: Request, props: MarkdownRouteProps) {
  const params = await props.params;
  const page = source.getPage(params.slug);

  if (!page) notFound();

  return new Response(await getLLMText(page), {
    headers: {
      'Content-Type': 'text/markdown; charset=utf-8',
    },
  });
}

export function generateStaticParams() {
  return source.generateParams();
}
