AI
LLMs 集成
Docus 使用 Nuxt LLMs 模块生成 AI-ready 内容文件
Docus 默认集成 nuxt-llms,为大型语言模型(LLMs)准备内容。所有文档页面都会被注入,并自动生成和预渲染 /llms.txt 与 /llms-full.txt 文件。
默认值
以下是生成 /llms.txt 文件时使用的默认值:
domain→ 基于部署平台计算(或使用NUXT_SITE_URL环境变量)title→ 从package.json提取description→ 从package.json提取full.title→ 从package.json提取full.description→ 从package.json提取
自定义
你可以在 nuxt.config.ts 中覆盖 LLMs 数据:
nuxt.config.ts
export default defineNuxtConfig({
llms: {
domain: 'https://your-site.com',
title: 'Your Site Name',
description: 'A brief description of your site',
full: {
title: 'Your Site Name',
description: 'A brief description of your site',
},
},
})
原始 Markdown 访问
启用 nuxt-llms 后,Docus 还会暴露原始 Markdown endpoint,让 AI agents 可以直接获取 LLM-ready 源文件,而无需经过完整渲染流程。这能减少 token 使用量,并提升 AI 工具消费文档时的响应速度。
工作方式
- Endpoint:
/raw/<content-path>.md— 使用与页面 URL 相同的路径,移除结尾的/index,并保留.md扩展名 - Content-Type:
text/markdown; charset=utf-8 - 自动补充:如果请求的文档缺少顶级标题或描述,路由会自动把标题和描述追加到 Markdown 正文前面
- LLMs.txt 集成:
llms.txt中的文档链接会自动重写为/raw/...mdendpoint,让 agents 获取紧凑 Markdown,而不是完整 HTML
配置
你可以在 nuxt.config.ts 中自定义原始 Markdown 行为:
nuxt.config.ts
export default defineNuxtConfig({
llms: {
contentRawMarkdown: {
// Prevent specific page collections from being exposed
excludeCollections: ['landing', 'landing_en', 'landing_fr'],
// Keep llms.txt links pointing to rendered pages instead of raw markdown
rewriteLLMSTxt: false,
},
},
})
要完全禁用原始 Markdown 访问:
nuxt.config.ts
export default defineNuxtConfig({
llms: {
contentRawMarkdown: false,
},
})
Markdown 重定向
此功能仅在 Docus 部署到 Vercel 时可用。等 Nitro v3 支持多供应商全局 rewrites 后,它就可以与平台无关。
部署到 Vercel 时,Docus 会自动配置智能路由,为 AI agents 和 CLI 工具提供 Markdown 内容。
为什么?
Claude Code 等 agents 默认使用 Accept: text/markdown header,返回原始 Markdown 可以在过程中节省大量数据传输和 token。
如何实现?
Docus 通过 HTTP headers 检测来自 AI agents 和命令行工具的请求:
- Accept header:带有
Accept: text/markdown的请求会自动重定向 - User-agent 检测:来自
curl这类 agents 的请求会自动重定向
重定向规则
- 根路径:
/→/llms.txt - 文档页面:
/{path}→/raw/{path}.md
使用示例
# 从首页获取 llms.txt
curl -H "Accept: text/markdown" https://docus.dev/
# 从 locale 首页获取 llms.txt
curl -H "Accept: text/markdown" https://docus.dev/en
# 获取文档页面的原始 Markdown
curl -H "Accept: text/markdown" https://docus.dev/zh-cn/ai/llms
这些命令都会返回 Markdown 内容,而不是 HTML。