Skip to content

armgit / pdfcn

Public Imported from GitHub
0

Beautiful pdf components, built on Takumi and Forme. 100% Free, Zero config, one command setup.

906 B
Raw Blame
import { notFound } from "next/navigation";

import { markdownResponse } from "@/lib/api";
import { getLLMText, getPageMarkdownUrl, source } from "@/lib/source";

export const revalidate = false;

const docsMarkdown = async (
  { params }: { params: Promise<{ slug?: string[] }> },
  includeBody: boolean
) => {
  const { slug } = await params;
  const page = source.getPage(slug?.slice(0, -1));
  if (!page) {
    notFound();
  }

  return markdownResponse(await getLLMText(page), includeBody);
};

export const GET = (
  _req: Request,
  context: { params: Promise<{ slug?: string[] }> }
) => docsMarkdown(context, true);

export const HEAD = (
  _req: Request,
  context: { params: Promise<{ slug?: string[] }> }
) => docsMarkdown(context, false);

export const generateStaticParams = () =>
  source.getPages().map((page) => ({
    lang: page.locale,
    slug: getPageMarkdownUrl(page).segments,
  }));