You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/guide/basic/ssg-md.mdx
+163-1Lines changed: 163 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,166 @@ tag: experimental
4
4
5
5
# llms.txt (SSG-MD)
6
6
7
-
{/* TODO */}
7
+
Rspress provides experimental SSG-MD capability, which is a brand new feature. As its name suggests SSG-MD, the only difference from [Static Site Generation (SSG)](./ssg) is that it renders your pages as Markdown files instead of HTML files, and generates [`llms.txt`](https://llmstxt.org/) and llms-full.txt related files, making it easier for large language models to understand and use your technical documentation.
8
+
9
+
## Why SSG-MD?
10
+
11
+
In frontend frameworks based on React dynamic rendering, there is often a problem of difficulty in extracting static information. This also exists in MDX, where `.mdx` files contain both Markdown content and support embedding React components, enhancing the interactivity of documents. For Rspress, Rspress allows users to use [MDX fragments](../use-mdx/components.mdx), custom components, React Hooks, tsx files as routes, etc. to enhance the expressiveness of document content. However, these dynamic contents are difficult to convert to Markdown format, and even if the html generated during the SSG phase is converted to markdown, the results are often unsatisfactory.
12
+
13
+
[Static Site Generation (SSG)](./ssg) can generate static HTML files for crawlers to crawl, improving [SEO](https://en.wikipedia.org/wiki/Search_engine_optimization). SSG-MD also solves similar problems, improving [GEO](https://en.wikipedia.org/wiki/Generative_engine_optimization) and the quality of static information for large language models. Compared to converting html to markdown, React's virtual DOM during rendering has a better source of information.
14
+
15
+
## How to implement SSG-MD?
16
+
17
+
1. Rspress internally implements a `renderToMarkdownString` method similar to `renderToString` in `react-dom`.
18
+
19
+
```tsx
20
+
import { expect, describe, it } from'@rstest/core';
2. Provides `process.env.__SSR_MD__` environment variable, making it easy for users to distinguish between SSG-MD rendering and browser rendering in MDX components, thus achieving more flexible content customization. For example:
54
+
55
+
```tsx
56
+
exportfunction Tab({ label }: { label:string }) {
57
+
if (process.env.__SSR_MD__) {
58
+
return <>{`** Here is a Tab named ${label}**`}</>;
59
+
}
60
+
return <div>{label}</div>;
61
+
}
62
+
```
63
+
64
+
3. Rspress internal component library has been adapted for SSG-MD to ensure reasonable Markdown content is rendered during the SSG-MD phase. For example:
We believe that with the introduction of this feature, all websites built with React in the future can use SSG-MD to achieve better GEO.
95
+
96
+
## Features
97
+
98
+
- Renders each site page as a `.md` file, convenient for vectorization or providing to large language models. `/guide/start/introduction.html` can be accessed by replacing the `.html` suffix with `.md`.
99
+
- Generates [`llms.txt`](https://llmstxt.org/), displaying the title and description of each page in navigation and sidebar order.
100
+
- Generates `llms-full.txt`, containing the Markdown content of each page, convenient for batch import.
101
+
- Supports multilingual sites, outputting corresponding `{lang}/llms.txt` and `{lang}/llms-full.txt` for non-default languages.
102
+
103
+
## Output example
104
+
105
+
```txt
106
+
doc_build
107
+
├── llms.txt
108
+
├── llms-full.txt
109
+
├── guide
110
+
│ └── start
111
+
│ └── introduction.md
112
+
└── ...
113
+
```
114
+
115
+
The actual files are placed in the build directory (such as `guide/start/introduction.md`), and the `url` in `llms-full.txt` will carry the site prefix, such as `/guide/start/introduction.md`.
116
+
117
+
`llms-full.txt` example snippet:
118
+
119
+
```md
120
+
---
121
+
url: /guide/start/introduction.md
122
+
---
123
+
124
+
# Introduction
125
+
126
+
...
127
+
```
128
+
129
+
## How to enable
130
+
131
+
Enable `llms` in `rspress.config.ts` to generate the above files during the build phase:
132
+
133
+
```ts title="rspress.config.ts"
134
+
import { defineConfig } from'@rspress/core';
135
+
136
+
exportdefaultdefineConfig({
137
+
llms: true,
138
+
});
139
+
```
140
+
141
+
After executing `rspress build`, you can see `llms.txt`, `llms-full.txt` and the `.md` files corresponding to each route in the output directory (default `doc_build`).
142
+
143
+
:::warning
144
+
145
+
`llms` is an experimental capability, mainly used to generate Markdown data that is easy for large language models or retrieval systems to use. It will be continuously optimized in future versions and may have stability or compatibility issues.
146
+
147
+
If your project does not support SSG, such as using `ssg: false`, please use [@rspress/plugin-llms](/plugin/official-plugins/llms).
148
+
149
+
:::
150
+
151
+
## Custom MDX splitting (Optional)
152
+
153
+
When documents contain custom components, you can control which components to keep or convert to plain text when converting to Markdown through `remarkSplitMdxOptions`:
154
+
155
+
```ts title="rspress.config.ts"
156
+
import { defineConfig } from'@rspress/core';
157
+
158
+
exportdefaultdefineConfig({
159
+
llms: {
160
+
remarkSplitMdxOptions: {
161
+
excludes: [[['Demo'], '@project/components']],
162
+
},
163
+
},
164
+
});
165
+
```
166
+
167
+
-`excludes`: Matched components will be converted to plain text, with the highest priority.
168
+
-`includes`: If set, only matched components are allowed to be retained, and the rest will be converted to plain text.
169
+
- When configured simultaneously, `excludes` will be applied first, then filtered by `includes`.
Copy file name to clipboardExpand all lines: website/docs/en/plugin/official-plugins/llms.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,12 @@ import { SourceCode } from '@rspress/core/theme';
8
8
9
9
Generate [llms.txt](https://llmstxt.org/) related files for your Rspress site, allowing large language models to better understand your documentation site.
10
10
11
+
:::warning
12
+
13
+
`@rspress/plugin-llms` is only intended as an alternative solution for scenarios where `ssg: false` is used. It is recommended to prioritize using the [SSG-MD](/guide/basic/ssg-md) feature.
[静态站点生成(SSG)](./ssg) 可以生成静态的 HTML 文件提供给爬虫爬取,提高 [SEO](https://en.wikipedia.org/wiki/Search_engine_optimization),SSG-MD 也为了解决类似的问题,提升 [GEO](https://en.wikipedia.org/wiki/Generative_engine_optimization) 和给大模型的静态信息质量,相比与将 html 转化为 markdown,React 在渲染期间的虚拟 DOM 拥有更好的信息源。
0 commit comments