|
| 1 | +import { conceptPagePath, startPagePath } from "../lib/utils"; |
| 2 | +import { site } from "../site"; |
| 3 | +import { FORMATS } from "./llms.txt"; |
| 4 | +import type { APIRoute } from "astro"; |
| 5 | +import { getCollection } from "astro:content"; |
| 6 | +import Handlebars from "handlebars"; |
| 7 | +import fs from "node:fs"; |
| 8 | +import path from "node:path"; |
| 9 | + |
| 10 | +const { url: root, title, description: tagline, llms } = site; |
| 11 | + |
| 12 | +const templateFile = fs.readFileSync( |
| 13 | + path.join(process.cwd(), "src/templates/llms-full.txt.hbs"), |
| 14 | + "utf-8", |
| 15 | +); |
| 16 | + |
| 17 | +const template = Handlebars.compile(templateFile); |
| 18 | + |
| 19 | +export const GET: APIRoute = async () => { |
| 20 | + const startPages = await getCollection("start"); |
| 21 | + const conceptPages = await getCollection("concepts"); |
| 22 | + |
| 23 | + const content = template({ |
| 24 | + root, |
| 25 | + title, |
| 26 | + system: |
| 27 | + "This is the complete documentation for Zero to Nix, including the learning journey (start) and concept pages.", |
| 28 | + instructions: |
| 29 | + "Learning journey (start) and concept page items begin and end with a --- and all page titles are in bold.", |
| 30 | + tagline, |
| 31 | + description: llms.description, |
| 32 | + startPages: startPages.map(({ data: { title }, slug, body }) => ({ |
| 33 | + title, |
| 34 | + href: `${root}/${startPagePath(slug)}`, |
| 35 | + content: body, |
| 36 | + })), |
| 37 | + conceptPages: conceptPages.map(({ data: { title }, slug, body }) => ({ |
| 38 | + title, |
| 39 | + href: `${root}/${conceptPagePath(slug)}`, |
| 40 | + content: body, |
| 41 | + })), |
| 42 | + otherFormats: [FORMATS.small, FORMATS.standard], |
| 43 | + }); |
| 44 | + |
| 45 | + return new Response(content, { |
| 46 | + headers: { |
| 47 | + "Content-Type": "text/plain; charset=utf-8", |
| 48 | + }, |
| 49 | + }); |
| 50 | +}; |
| 51 | + |
| 52 | +export const prerender = true; |
0 commit comments