llms.txt 与 Markdown 导出¶
llmstxt自 v0.0.67 起原生支持,为站点生成llms.txt索引,并把选中的页面导出为 Markdown 副本——让 AI 工具更容易读懂你的文档。
为什么需要 llms.txt¶
llms.txt 是一种面向大语言模型的站点索引约定:用一个纯文本文件列出站点的关键页面与其 Markdown 版本链接。Zensical 会在生成的站点中同时提供:
llms.txt索引文件- 所选页面的
.md副本 - UI 中新增的 llms.txt / Markdown 发现链接(v0.0.70 起)
- 可选的"Copy as Markdown"按钮(需配合主题特性)
启用与配置¶
zensical.toml
[project.plugins.llmstxt]
sections = [
{ title = "教程", pages = ["tutorials/*.md"] },
{ title = "博客", pages = ["blog/**/*.md"] },
]
[project.plugins.llmstxt]
enabled = true
sections = [
{ title = "入门", pages = ["getting-started/*.md"] },
]
markdown_description = "Zensical 中文教程的 Markdown 版本"
full_output = "llms-full.txt"
plugins:
- llmstxt:
sections:
- title: 入门
pages:
- getting-started/*.md
官方配置项¶
| 配置项 | 默认值 | 说明 |
|---|---|---|
enabled |
true |
启用 llms.txt 生成 |
sections |
必填 | 命名分区及要包含的源页面,路径支持 glob |
markdown_description |
null |
追加到站点描述后的 Markdown 文本 |
base_url |
site_url |
生成 Markdown 页面链接时使用的基础 URL |
full_output |
null |
可选:包含所选页面全文的文件路径 |
autoclean |
true |
转 Markdown 前清理生成的 HTML |
Copy as Markdown 按钮¶
当主题 features 包含 content.action.copy 时,有 Markdown 副本的页面会显示"Copy as Markdown"按钮:
zensical.toml
[project.theme]
features = [
"content.action.copy",
]
行为差异与限制¶
以下 MkDocs 行为在 Zensical 中不同
preprocess被静默忽略:自定义 Python 预处理函数不会运行full_output必须是site_dir内的相对路径,不能等于llms.txt;绝对路径及空的、.、..路径组件会被拒绝- 即使
autoclean = false,mkdocstrings的源码列表和空代码元素也会被省略
输出文件¶
构建后在 site/ 目录查看:
llms.txt— 索引文件- 各页面的
.md副本(路径与源页面对应) full_output指定的全文文件(如配置了)