llms.txt Generator
Zurück zu Integrationen

llms.txt in Astro einbinden – Anleitung

llms.txt in Astro einzubinden ist denkbar einfach. Astro eignet sich durch seinen Content-First-Ansatz besonders gut für die Bereitstellung von llms.txt-Dateien.

Option 1: Statische Datei

my-astro-app/
├── public/
│   ├── llms.txt          ← Deine llms.txt
│   ├── llms-full.txt     ← Optional
│   └── robots.txt
├── src/
│   ├── pages/
│   └── content/
└── astro.config.mjs

Wie bei anderen Frameworks werden Dateien in public/ unverändert im Root bereitgestellt.

Option 2: Dynamischer Endpoint

Astro unterstützt Endpoints für dynamische Inhalte:

// src/pages/llms.txt.ts
import type { APIRoute } from 'astro'

export const GET: APIRoute = async () => {
  const content = `# Meine Website

> Kurze Beschreibung meiner Website

- [Home](/): Willkommen auf unserer Seite
- [Blog](/blog): Fachartikel und News
- [Kontakt](/kontakt): So erreichst du uns`

  return new Response(content, {
    headers: {
      'Content-Type': 'text/plain; charset=utf-8',
    },
  })
}

Mit Content Collections generieren

Astros Content Collections eignen sich perfekt für die automatische Generierung:

// src/pages/llms.txt.ts
import type { APIRoute } from 'astro'
import { getCollection } from 'astro:content'

export const GET: APIRoute = async () => {
  const posts = await getCollection('blog')
  const pages = await getCollection('pages')

  let content = '# Meine Website\n\n'
  content += '> Blog und Wissensportal\n\n'
  content += '## Seiten\n\n'

  for (const page of pages) {
    content += `- [${page.data.title}](/${page.slug})`
    if (page.data.description) {
      content += `: ${page.data.description}`
    }
    content += '\n'
  }

  content += '\n## Blog\n\n'
  for (const post of posts) {
    content += `- [${post.data.title}](/blog/${post.slug}): ${post.data.description || ''}\n`
  }

  return new Response(content, {
    headers: { 'Content-Type': 'text/plain' },
  })
}

SSG vs. SSR

Im Standard-SSG-Modus wird der Endpoint beim Build generiert – die Datei ist dann statisch. Im SSR-Modus (mit output: 'server' in astro.config.mjs) wird sie bei jedem Request dynamisch erzeugt. Für die meisten Websites reicht die statische Variante.

Verwandte Themen

Jetzt llms.txt generieren

Kostenlos bis 20 Seiten. Keine Registrierung.

Jetzt starten