llms.txt
An /llms.txt endpoint that lists your pages and posts for AI tools, built from your collections.
Native .astro · no React · MIT · free, no account
Install
npx shadcn@latest add https://www.themes.dev/astro/r/llms-txt.jsonThe CLI needs a components.json (from npx shadcn init), which also writes the tokens these files use. No CLI? Copy the files below to the same paths.
Files
// /llms.txt: a plain-text map of the site for AI tools (the llmstxt.org format): the site's name, one line about// it, then sections of links with a short note each. Build it from your collections so it never goes stale.import type { APIContext } from 'astro';import { getCollection } from 'astro:content'; export async function GET(context: APIContext) { const site = context.site!; const posts = (await getCollection('posts')).sort((a, b) => +new Date(b.data.date) - +new Date(a.data.date)); const link = (title: string, path: string, note?: string) => `- [${title}](${new URL(path, site).href})${note ? `: ${note}` : ''}`; const body = [ '# Your site', '', '> One sentence about what the site is and who it is for.', '', '## Pages', link('Home', '/'), link('About', '/about/', 'who we are'), '', '## Posts', ...posts.map((p) => link(p.data.title, `/blog/${p.id}/`, p.data.summary)), '', ].join('\n'); return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });}More for site
- Theme toggleFreeA 36px button that switches light and dark and remembers the choice, plus the head script that prevents a flash.ThemeToggle.astro · ThemeScript.astro
- RSS feedFreeAn /rss.xml endpoint from a content collection with @astrojs/rss.rss.xml.ts
- robots.txtFreeA /robots.txt endpoint with your sitemap's address and the paths to keep out of search.robots.txt.ts