Nuxt Content 模块集成了 nuxt-llms,用于为大型语言模型 (LLMs) 准备内容。当检测到 nuxt-llms 时,Content 模块会自动扩展 LLMs 模块,并将类型为 page 的集合注入到 LLMs 模块中。🚀
npm install nuxt-llms
nuxt.config.tsexport default defineNuxtConfig({
modules: ['@nuxt/content', 'nuxt-llms'],
llms: {
domain: 'https://your-site.com',
title: '你的站点名称',
description: '你站点的简要描述',
},
})
就是这么简单 🚀 /llms.txt 文件会被自动生成并预渲染。
启用 nuxt-llms 后,Nuxt Content 还会暴露一个原始 markdown 端点,使你可以直接流式获取适用于 LLM 的源文件,而无需通过完整的渲染管道。
/raw/<content-path>.md(路径与页面 URL 相同,去除末尾的 /index,保留 .md 扩展名),返回 text/markdown; charset=utf-8。page 集合;可通过 llms.contentRawMarkdown.excludeCollections 排除特定集合。设置 llms.contentRawMarkdown = false 可完全禁用该端点。llms.txt 中生成的文档链接会自动重写为 /raw/...md 端点(除非集合被排除或功能关闭),这样代理可以获取精简的 markdown,而非完整 HTML,减少 tokens 使用并提升响应速度。通过 llms.contentRawMarkdown.rewriteLLMSTxt 控制(默认启用 true)。export default defineNuxtConfig({
modules: ['@nuxt/content', 'nuxt-llms'],
llms: {
contentRawMarkdown: {
// 可选:防止暴露特定 page 集合
excludeCollections: ['blog'],
// 可选:保持 llms.txt 链接指向渲染页面
rewriteLLMSTxt: false,
},
},
})
在生成内容时,你可以创建自定义分区,将内容处理为适合 LLM 使用的格式。
你可以向 llms.sections 数组中添加自定义分区,并为每个分区定义 contentCollection 和 contentFilters 选项。
contentCollection 选项中未定义分区,模块将仅把 page 集合添加到 LLMs 模块。contentCollection此选项指定要使用哪个内容集合作为来源。
export default defineNuxtConfig({
llms: {
sections: [
{
title: '文档',
description: '技术文档和指南',
contentCollection: 'docs',
},
],
},
})
contentFilters此选项定义用于选择集合中特定内容的过滤器。
你可以精确控制包含哪些内容。每个过滤器包含:
field:要检查的内容属性operator:比较运算符(=、<>、>、<、LIKE、IN、NOT IN、IS NULL、IS NOT NULL 等)value:比较的值export default defineNuxtConfig({
llms: {
sections: [
{
title: '文档',
description: '技术文档和指南',
contentCollection: 'docs',
contentFilters: [
// 只包含 Markdown 文件
{ field: 'extension', operator: '=', value: 'md' },
// 只包含已发布的内容
{ field: 'draft', operator: '<>', value: true },
// 按目录过滤
{ field: 'path', operator: 'LIKE', value: '/guide%' },
]
},
],
},
})