An idiomatic /llms.txt route for Astro — a thin wrapper over @arraypress/llms-txt's build(). Same options, returned as a Response, with the site origin resolved for you.
npm install @arraypress/llms-txt-astroDrop a file at src/pages/llms.txt.ts. Astro serves it at /llms.txt and prerenders it with the rest of a static build.
import { llmsTxtRoute } from '@arraypress/llms-txt-astro';
import { posts } from '../data/posts';
export const GET = llmsTxtRoute((origin) => ({
name: 'My Site',
description: 'What this site is, in one line.',
sections: [
{
title: 'Writing',
links: posts.map((p) => ({ label: p.title, url: `${origin}/${p.slug}` })),
},
],
}));For a file with no absolute URLs, pass the options directly:
export const GET = llmsTxtRoute({ name: 'My Site', description: 'One line.' });Returns an Astro APIRoute serving text/plain.
options is either a build() options object, or a factory (origin, context) => options — sync or async. The factory form is the usual one, since the spec wants absolute URLs and the origin isn't known until the request.
The resolved origin, no trailing slash. Prefers Astro's configured site; falls back to the request URL's origin when site is unset, so astro dev emits usable links instead of undefined/…. Exported because a page occasionally needs the same value.
@arraypress/llms-txt is zero-dependency and runs anywhere. This package adds the two things every Astro site otherwise reimplements — resolving Astro.site down to a bare origin, and wrapping the result in a Response — without pulling Astro into the core library.
MIT