import { getPublishedMarketingBlogPostsPage } from "@/lib/marketing-blog";
import { getPublicSiteAbsoluteUrl } from "@/lib/mail-urls";
import { buildLlmsIndex } from "@/lib/public-discovery";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

export async function GET() {
  const page = await getPublishedMarketingBlogPostsPage({ limit: 24 }).catch(() => ({
    hasMore: false,
    posts: [],
  }));

  return new Response(buildLlmsIndex(page.posts), {
    headers: {
      "Cache-Control": "public, s-maxage=900, stale-while-revalidate=86400",
      "Content-Language": "ko-KR",
      "Content-Type": "text/markdown; charset=utf-8",
      "Link": `<${getPublicSiteAbsoluteUrl("/llms.txt")}>; rel="canonical"`,
    },
  });
}
