GitHub Pages向けllms.txt
GitHub Pages には 3 つのアプローチがあります。docs/ または gh-pages にコミットされた静的ファイル、コンテンツを自動生成する Jekyll テンプレート、あるいは完全自動生成のための GitHub Actions ワークフローです。
最終更新:
選択肢1:docs/またはgh-pages内の静的ファイル
最も簡単な方法は、 llms.txt プレーンファイルとしてリポジトリにコミットするのが最も簡単です。GitHub
Pages は正しい MIME タイプのまま配信します。
# 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:layout: nullを使用するJekyll
GitHub Pages サイトが Jekyll(多くのリポジトリのデフォルト)を使っているなら、プレーンな .txt ファイルは変更されずにそのまま処理されるため、フロントマターは不要です。ただし、Jekyll
でファイルをテンプレートとして処理したい場合(サイト変数の挿入など)は、次のフロントマターブロックを追加します:
layout: null を指定して、Jekyll が HTML レイアウトでラップしないようにします。
---
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
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."
---
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
# 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
// 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), 追加する CNAME ファイルを、ドメインを含むドキュメントディレクトリに置きます。GitHub Pagesは、
llms.txtそのドメインで、
myproject.com
絶対 URL を使用してください。 llms.txt では、独自ドメインに一致する URL を指定します。次の既定ドメインは使用しません:
username.github.io/repo URL。
検証
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 関連ガイド
- llms.txtの作成方法、テンプレート、チェックリスト。
- llms.txt フォーマットリファレンス、仕様の詳細。
- Eleventyガイド、もう一つの静的サイトジェネレータ。
- Hugoガイド、Goテンプレートを使用する静的サイト。
- バリデータ · ジェネレーター.