Eleventy(11ty)向けllms.txt

Eleventyのテンプレートシステムなら、llms.txtを簡単に作成できます。permalinkのfrontmatterキーを持つプレーンテキストファイルを使用するか、コレクションをループしてコンテンツからリンクを自動生成します。

最終更新:

選択肢1: プレーンテキストテンプレート

以下の場所にファイルを作成してください: src/llms.txt (または入力ディレクトリ内の任意の場所)。 permalink キーをYAMLフロントマターに指定して出力パスを制御します。Eleventyがファイルを処理し、 _site/llms.txt.

src/llms.txt
---
permalink: /llms.txt
eleventyExcludeFromCollections: true
---
# Your Site

> One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure in minutes.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog with examples.

## Product

- [Overview](https://yoursite.com/product): Core features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing details.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
eleventy.config.js, enable txt templates
// eleventy.config.js
module.exports = function (eleventyConfig) {
  // Add passthrough copy for any assets you want served verbatim
  // llms.txt is handled via permalink in the template, no passthrough needed

  // Optional: add a collection for docs
  eleventyConfig.addCollection('docs', function (collectionApi) {
    return collectionApi.getFilteredByGlob('src/docs/**/*.md');
  });

  // Ensure .txt files are processed as templates
  return {
    templateFormats: ['md', 'njk', 'html', 'txt'],
    dir: {
      input: 'src',
      output: '_site',
    },
  };
};

オプション 2:コレクションから生成する

ドキュメントが frontmatter 付きの Markdown ファイルによる Eleventy コレクションとして管理されている場合は、 テンプレート内でコレクションをループして、リンク一覧を自動生成できます。 ---js JavaScript ベースの設定には frontmatter 構文を、本文には Nunjucks/Liquid テンプレート構文を使用します。

src/llms.txt, from collections
---js
{
  permalink: "/llms.txt",
  eleventyExcludeFromCollections: true
}
---
# Your Site

> {{ site.description }}

## Documentation

{% for doc in collections.docs | sort(attribute='data.order') -%}
- [{{ doc.data.title }}]({{ site.url }}{{ doc.url }}): {{ doc.data.description }}
{% endfor %}

site.url グローバルデータ変数は次で設定する必要があります: _data/site.js または _data/site.json ファイル。すべてのリンクで絶対URLを使用してください。 AIクローラーが取得した際、相対パスは正しく解決されません。

利用する llms.txt テンプレートの主要なフロントマターオプション: llms.txt テンプレート:

  • permalink: /llms.txt、ファイルをサイトのルートディレクトリに出力してください。
  • eleventyExcludeFromCollections: trueにより、ファイルがサイトのコレクション(ナビゲーション、フィード、サイトマップ)に現れないようにします。
  • layout: false。これによりレイアウトのラッパーが適用されません( .txt ファイルではデフォルトでHTMLレイアウトを使用しないためです)。

検証

Eleventy のビルドを実行し、出力を確認します:

Build and verify
# Build
npx @11ty/eleventy

# Check that the file was generated
cat _site/llms.txt | head -5

# After deploying, verify the live URL
curl -I https://yoursite.com/llms.txt
# Expected: content-type: text/plain; charset=utf-8

関連ガイド

ソース