pengzhanbo b1f996cb0e
feat(plugin-md-power): add ::: encrypt container, close #815 (#831)
* feat(plugin-md-power): add `::: encrypt` container

* chore: tweak

* chore: tweak

* chore: tweak
2026-02-12 23:55:21 +08:00

155 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: LLMs txt
icon: ri:ai
createTime: 2025/12/01 10:45:29
permalink: /guide/features/llmstxt/
---
## 概述
为站点添加 [llms.txt](https://llmstxt.org/),以提供对 LLM 友好的内容。
**关联插件** [@vuepress/plugin-llms](https://ecosystem.vuejs.press/zh/plugins/ai/llms.html)
## 为什么需要 llms.txt
大型语言模型越来越依赖网站信息,但面临一个关键限制:上下文窗口太小,无法完整处理大多数网站。将包含导航、广告和 JavaScript 的复杂 HTML 页面转换为适合 LLM 的纯文本既困难又不精确。
虽然网站同时为人类读者和 LLM 服务,但后者受益于在一个可访问的位置收集的更简洁、专家级的信息。这对于开发环境等使用案例尤其重要,因为 LLM 需要快速访问编程文档和 API。
向网站添加 `/llms.txt` Markdown 文件,以提供对 LLM 友好的内容。此文件提供了简短的背景信息、指南和指向详细 Markdown 文件的链接。
## 功能
插件通过检索你的文档源目录中的所有 Markdown 文件,并将其转换为 LLM 友好的纯文本文件。
::: file-tree
- .vuepress/dist
- llms.txt
- llms-full.txt
- markdown-examples.html
- markdown-examples.md
-
:::
点击以下链接查看本文档站点的 llms.txt 文件:
- [llms.txt](/llms.txt){.no-icon}
- [llms-full.txt](/llms-full.txt){.no-icon}
::: tip
插件仅在生产构建时,即执行 `vuepress build` 命令时,生成 `llms.txt` 文件,以及其它 LLM 友好的文档文件,并将它们输出到 `.vuepress/dist` 目录中。
:::
[完整功能说明请查看 **插件官方文档**](https://ecosystem.vuejs.press/zh/plugins/ai/llms.html#%E6%8F%92%E4%BB%B6%E5%8A%9F%E8%83%BD){.read-more}
## 配置
主题默认不启用此功能,你可以通过 `llmstxt` 配置项启用它:
```ts title=".vuepress/config.ts"
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
// 使用主题内置的默认配置
// llmstxt: true,
// 使用自定义配置
llmstxt: {
locale: '/',
// ...其它配置
},
// 也可以在 `plugins.llmstxt` 配置,但不推荐
plugins: {
llmstxt: true
}
}),
})
```
[完整配置项说明请查看 **插件官方文档**](https://ecosystem.vuejs.press/zh/plugins/ai/llms.html#options){.read-more}
## 组件
为进一步增强 文档站点 与 LLMs 的互动,你可以在文档站点中添加 `<PageContextMenu />` 组件。
该组件不作为内置组件,而是主题额外的 `features` 实现,因此你需要手动引入它,
并在合适的位置,通过 [组件插槽](../../guide/custom/slots.md) 添加到文档站点中:
```ts title=".vuepress/client.ts"
import { defineAsyncComponent, h } from 'vue'
import { Layout } from 'vuepress-theme-plume/client'
import PageContextMenu from 'vuepress-theme-plume/features/PageContextMenu.vue' // [!code ++]
import { defineClientConfig } from 'vuepress/client'
export default defineClientConfig({
layouts: {
Layout: h(Layout, null, {
// 将 PageContextMenu 添加到 doc-title-after 插槽,即文章标题的右侧
'doc-title-after': () => h(PageContextMenu), // [!code ++]
}),
},
})
```
你可以在当前页面的标题的右侧,体验该组件的功能。
::: important
此组件完全依赖于 `@vuepress/plugin-llms` 插件,仅当你启用了此插件功能后,才能使用它。
因此,此组件提供的功能 **仅在构建后的生产包中才可用** 。
:::
## 扩展标记 (Markup)
### `<llm-only>`
你可以在文件中添加对 LLM 可见但对人类不可见的内容,这有助于设置特殊指令,
例如 “参考 basic-queries 获取演示”、“切勿执行……”、“在……情况下始终使用……”等。
为此,需要使用 `<llm-only>` 标签来包裹内容。
```md
<llm-only>
## Section for LLMs
此内容仅出现在生成的LLM文件中不会包含 `<llm-only>` 标签本身。
</llm-only>
```
也可以在单行中使用 `<llm-only>` 标签,但请注意单行时仅能包含一个 `<llm-only>` 标签,否则会导致解析错误。
```md
查看插件API指南了解创建插件的相关文档。
<llm-only>仅限 LLM 阅读</llm-only>
```
### `<llm-exclude>`
你可以在文件中添加对人类可见但对LLM不可见的内容这与 `<llm-only>` 的作用相反:
```md
<llm-exclude>
## Section for humans
此内容将不会出现在为 LLMs 生成的文件中
</llm-exclude>
```
也可以在单行中使用 `<llm-exclude>` 标签,但请注意单行时仅能包含一个 `<llm-only>` 标签,否则会导致解析错误。
```md
查看插件API指南了解创建插件的相关文档。
<llm-exclude>仅限人类阅读</llm-exclude>
```