<!-- Generated from zh/llms-txt-eleventy/index.html. The canonical document is the HTML page. -->

- [ 首页 ](/zh/) 
/
- [ 如何创建 ](/zh/how-to-create/) 
/
- Eleventy 指南            
# Eleventy（11ty）的 `llms.txt`

Eleventy 的模板系统让 llms.txt 的实现非常直接：使用带 permalink frontmatter 键的纯文本文件，或遍历集合，根据内容自动生成链接。

最近更新: 2026年4月22日

本页内容

- [ 选项 1：纯文本模板 ](#static)
- [ 选项 2：从集合中生成 ](#dynamic)
- [ 永久链接配置 ](#permalink)
- [ 验证 ](#verify)            
## 方案 1：纯文本模板

在 `src/llms.txt` （或输入目录中的任意位置）。添加一个 `permalink` 键，以控制输出路径。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.

```

示例

将 txt 添加到 templateFormats

默认情况下，Eleventy 不处理  .txt  文件作为模板处理。将  'txt'  到  templateFormats  数组放入你的  eleventy.config.js 。请参阅下面的配置片段。
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：从集合中生成

如果你的文档以 Eleventy 集合的形式管理（带有 frontmatter 的 Markdown
文件），可以在模板内遍历集合并自动生成链接列表。使用 `---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 爬虫获取时无法正确解析。

## 永久链接配置

以下是你的关键 frontmatter 选项： `llms.txt` 模板：

- `permalink: /llms.txt`，将文件输出到网站根目录。 
- `eleventyExcludeFromCollections: true`，可防止该文件出现在你的
站点集合（nav、feeds、sitemaps）中。 
- `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
```

## 相关指南

- [如何创建 llms.txt](/zh/how-to-create/)、模板和检查清单。 
- [llms.txt 格式参考](/zh/llms-txt-format/)，规范细节。 
- [Hugo 指南](/zh/llms-txt-hugo/)，类似的静态网站生成器方法。 
- [Gatsby 指南](/zh/llms-txt-gatsby/)，基于 React 的静态生成。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).        
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ Eleventy 文档，永久链接 ](https://www.11ty.dev/docs/permalinks/)
- [ Eleventy 文档，集合 ](https://www.11ty.dev/docs/collections/)
