llms.txt для GitHub Pages

Три подхода для GitHub Pages: статический файл, зафиксированный в docs/ или gh-pages, шаблон Jekyll для автоматической генерации content или рабочий процесс GitHub Actions для полностью автоматической генерации.

Последнее обновление:

Вариант 1: статический файл в docs/ или gh-pages

Самый простой подход — зафиксировать в коммите llms.txt как обычный файл в репозиторий. GitHub Pages отдаёт его как есть с правильным MIME-типом.

GitHub Pages directory structure
# GitHub Pages, static file approach
#
# Serving from docs/ branch (most common):
#   your-repo/
#   ├── docs/
#   │   ├── index.html
#   │   └── llms.txt   ← add this file here
#   └── README.md
#
# Serving from gh-pages branch:
#   Create or switch to the gh-pages branch, then add:
#   llms.txt   ← in the branch root
#
# In repository Settings → Pages:
#   Source: Deploy from a branch
#   Branch: main (or gh-pages), Folder: /docs (or /)
#
# GitHub Pages serves it at: https://username.github.io/repo/llms.txt
# With a custom domain: https://yourdomain.com/llms.txt

GitHub Pages автоматически распознаёт обычные текстовые файлы и отдаёт их с Content-Type: text/plain; charset=utf-8. Настройка не требуется.

Вариант 2: Jekyll с layout: null

Если ваш сайт GitHub Pages использует Jekyll (по умолчанию для многих репозиториев), обычный .txt файл будет передан без изменений, front matter не требуется. Однако если вы хотите, чтобы Jekyll обрабатывал файл как шаблон (например, подставлял переменные сайта), добавьте блок front matter с layout: null чтобы Jekyll не оборачивал его в HTML-макет.

llms.txt, with Jekyll front matter
---
layout: null
permalink: /llms.txt
---
# My Project

> One-sentence description of what my project does.

## Documentation

- [Getting Started](https://myproject.com/docs/start/): Install and configure.
- [API Reference](https://myproject.com/docs/api/): Full endpoint catalog.

## Optional

- [Changelog](https://myproject.com/changelog/): Release history.

Список ссылок также можно получать из файла данных YAML в _data/, отделив содержимое от шаблона:

_data/llms_links.yml
# _data/llms_links.yml
docs:
  - title: "Getting Started"
    url: "https://myproject.com/docs/start/"
    desc: "Install and configure in minutes."
  - title: "API Reference"
    url: "https://myproject.com/docs/api/"
    desc: "Full endpoint catalog with examples."
optional:
  - title: "Changelog"
    url: "https://myproject.com/changelog/"
    desc: "Release history."
llms.txt, Jekyll template with _data
---
layout: null
permalink: /llms.txt
---
# {{ site.title }}

> {{ site.description }}

## Documentation
{% for link in site.data.llms_links.docs %}
- [{{ link.title }}]({{ link.url }}): {{ link.desc }}
{% endfor %}

## Optional
{% for link in site.data.llms_links.optional %}
- [{{ link.title }}]({{ link.url }}): {{ link.desc }}
{% endfor %}

Вариант 3: GitHub Actions для динамической генерации

Для сайтов, где список ссылок должен автоматически создаваться из содержимого (файлов Markdown, frontmatter, CMS), используйте рабочий процесс GitHub Actions, который запускает скрипт и фиксирует результат обратно в репозитории.

.github/workflows/generate-llms-txt.yml
# .github/workflows/generate-llms-txt.yml
# Generates llms.txt from your content and commits it to the repo.
name: Generate llms.txt

on:
  push:
    branches: [main]
    paths:
      - 'docs/**'
      - 'content/**'
  workflow_dispatch:

jobs:
  generate:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Generate llms.txt
        run: node scripts/generate-llms-txt.js

      - name: Commit and push if changed
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add docs/llms.txt
          git diff --staged --quiet || git commit -m "chore: regenerate llms.txt"
          git push
scripts/generate-llms-txt.js
// scripts/generate-llms-txt.js
// Run by GitHub Actions to generate docs/llms.txt from your content
const fs = require('fs');
const path = require('path');

const SITE_URL = 'https://myproject.com';

// Example: build link list from your markdown files in docs/
const docsDir = path.join(__dirname, '..', 'docs');
const mdFiles = fs.readdirSync(docsDir)
  .filter(f => f.endsWith('.md') && f !== 'index.md');

const links = mdFiles.map(file => {
  const content = fs.readFileSync(path.join(docsDir, file), 'utf-8');
  const titleMatch = content.match(/^#\s+(.+)/m);
  const descMatch = content.match(/^>\s+(.+)/m);
  const slug = file.replace('.md', '');
  const title = titleMatch ? titleMatch[1] : slug;
  const desc = descMatch ? descMatch[1] : '';
  return `- [${title}](${SITE_URL}/docs/${slug}/): ${desc}`;
}).join('\n');

const output = [
  '# My Project',
  '',
  '> My project description.',
  '',
  '## Documentation',
  '',
  links,
  '',
  '## Optional',
  '',
  `- [Changelog](${SITE_URL}/changelog/): Release history.`,
].join('\n');

fs.writeFileSync(path.join(docsDir, 'llms.txt'), output, 'utf-8');
console.log('Generated docs/llms.txt');

Рабочий процесс запускается при отправке изменений в main которые изменяют каталоги с контентом и могут также запускаться вручную через workflow_dispatch. Коммит создаётся только если сгенерированный файл действительно изменился.

Пользовательский домен и CNAME

Если вы используете собственный домен (например, myproject.com), добавьте a CNAME файл в каталоге документации, содержащий ваш домен. GitHub Pages будет обслуживать ваш сайт, включая llms.txt, на этом домене.

docs/CNAME
myproject.com

Используйте абсолютные URL в своём llms.txt соответствующие вашему пользовательскому домену, а не домену по умолчанию username.github.io/repo URL.

Проверить

Verification
curl -I https://myproject.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

curl https://myproject.com/llms.txt | head -5

Связанные руководства

Источники