@rspress/plugin-llms 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +82 -49
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -110,7 +110,21 @@ async function normalizeMdFile(content, filepath, routeService, base, mdxToMd, i
|
|
|
110
110
|
if ('' === result.trim()) return '\n';
|
|
111
111
|
return result;
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
function resolveNavForVersion(nav, version, defaultVersion) {
|
|
114
|
+
return nav.flatMap(({ nav, lang })=>{
|
|
115
|
+
let navArray;
|
|
116
|
+
if (Array.isArray(nav)) navArray = nav;
|
|
117
|
+
else {
|
|
118
|
+
const navObj = nav;
|
|
119
|
+
navArray = navObj[version] ?? navObj[defaultVersion] ?? navObj.default ?? [];
|
|
120
|
+
}
|
|
121
|
+
return navArray.map((item)=>({
|
|
122
|
+
...item,
|
|
123
|
+
lang
|
|
124
|
+
}));
|
|
125
|
+
}).filter((i)=>i.activeMatch || i.link);
|
|
126
|
+
}
|
|
127
|
+
const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, titleRef, descriptionRef, langRef, sidebar, routeServiceRef, nav, versionsRef, defaultVersionRef, rspressPluginOptions, index = 0 })=>({
|
|
114
128
|
name: `rsbuild-plugin-llms-${index}`,
|
|
115
129
|
async setup (api) {
|
|
116
130
|
const { llmsTxt = {
|
|
@@ -123,41 +137,61 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
|
|
|
123
137
|
}, include, exclude } = rspressPluginOptions;
|
|
124
138
|
api.onBeforeBuild(async ()=>{
|
|
125
139
|
const disableSSG = disableSSGRef.current;
|
|
140
|
+
const versions = versionsRef.current;
|
|
141
|
+
const defaultVersion = defaultVersionRef.current;
|
|
142
|
+
const isMultiVersion = versions.length > 0;
|
|
126
143
|
const newPageDataList = mergeRouteMetaWithPageData(routes, pageDataList, langRef.current, include, exclude);
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
});
|
|
146
|
-
for (const array of pageArray)organizeBySidebar(sidebar, array);
|
|
147
|
-
if (llmsTxt) {
|
|
148
|
-
const { name } = llmsTxt;
|
|
149
|
-
const llmsTxtContent = generateLlmsTxt(pageArray, navList, others, llmsTxt, titleRef.current, descriptionRef.current, baseRef.current);
|
|
150
|
-
api.processAssets({
|
|
151
|
-
environments: disableSSG ? [
|
|
152
|
-
'web'
|
|
153
|
-
] : [
|
|
154
|
-
'node'
|
|
155
|
-
],
|
|
156
|
-
stage: 'additional'
|
|
157
|
-
}, async ({ compilation, sources })=>{
|
|
158
|
-
const source = new sources.RawSource(llmsTxtContent);
|
|
159
|
-
compilation.emitAsset(name, source);
|
|
144
|
+
const versionList = isMultiVersion ? versions : [
|
|
145
|
+
''
|
|
146
|
+
];
|
|
147
|
+
for (const version of versionList){
|
|
148
|
+
const navList = resolveNavForVersion(nav, version, defaultVersion);
|
|
149
|
+
const versionPages = isMultiVersion ? new Map([
|
|
150
|
+
...newPageDataList.entries()
|
|
151
|
+
].filter(([, pageData])=>pageData.version === version)) : newPageDataList;
|
|
152
|
+
const others = [];
|
|
153
|
+
const pageArray = new Array(navList.length).fill(0).map(()=>[]);
|
|
154
|
+
versionPages.forEach((pageData)=>{
|
|
155
|
+
const { routePath, lang } = pageData;
|
|
156
|
+
for(let i = 0; i < pageArray.length; i++){
|
|
157
|
+
const pageArrayItem = pageArray[i];
|
|
158
|
+
const navItem = navList[i];
|
|
159
|
+
if (lang === navItem.lang && new RegExp((navItem.activeMatch ?? navItem.link).replace(/\.html$/, '')).test(routePath)) return void pageArrayItem.push(pageData);
|
|
160
|
+
}
|
|
161
|
+
others.push(pageData);
|
|
160
162
|
});
|
|
163
|
+
for (const array of pageArray)organizeBySidebar(sidebar, array);
|
|
164
|
+
const versionPrefix = isMultiVersion && version !== defaultVersion ? `${version}/` : '';
|
|
165
|
+
if (llmsTxt) {
|
|
166
|
+
const name = `${versionPrefix}${llmsTxt.name}`;
|
|
167
|
+
const llmsTxtContent = generateLlmsTxt(pageArray, navList, others, llmsTxt, titleRef.current, descriptionRef.current, baseRef.current);
|
|
168
|
+
api.processAssets({
|
|
169
|
+
environments: disableSSG ? [
|
|
170
|
+
'web'
|
|
171
|
+
] : [
|
|
172
|
+
'node'
|
|
173
|
+
],
|
|
174
|
+
stage: 'additional'
|
|
175
|
+
}, async ({ compilation, sources })=>{
|
|
176
|
+
const source = new sources.RawSource(llmsTxtContent);
|
|
177
|
+
compilation.emitAsset(name, source);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (llmsFullTxt) {
|
|
181
|
+
const name = `${versionPrefix}${llmsFullTxt.name}`;
|
|
182
|
+
const llmsFullTxtContent = generateLlmsFullTxt(pageArray, navList, others, baseRef.current);
|
|
183
|
+
api.processAssets({
|
|
184
|
+
targets: disableSSG ? [
|
|
185
|
+
'web'
|
|
186
|
+
] : [
|
|
187
|
+
'node'
|
|
188
|
+
],
|
|
189
|
+
stage: 'additional'
|
|
190
|
+
}, async ({ compilation, sources })=>{
|
|
191
|
+
const source = new sources.RawSource(llmsFullTxtContent);
|
|
192
|
+
compilation.emitAsset(name, source);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
161
195
|
}
|
|
162
196
|
const mdContents = {};
|
|
163
197
|
await Promise.all([
|
|
@@ -189,21 +223,6 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
|
|
|
189
223
|
compilation.emitAsset(`.${outFilePath}`, source);
|
|
190
224
|
});
|
|
191
225
|
});
|
|
192
|
-
if (llmsFullTxt) {
|
|
193
|
-
const { name } = llmsFullTxt;
|
|
194
|
-
const llmsFullTxtContent = generateLlmsFullTxt(pageArray, navList, others, baseRef.current);
|
|
195
|
-
api.processAssets({
|
|
196
|
-
targets: disableSSG ? [
|
|
197
|
-
'web'
|
|
198
|
-
] : [
|
|
199
|
-
'node'
|
|
200
|
-
],
|
|
201
|
-
stage: 'additional'
|
|
202
|
-
}, async ({ compilation, sources })=>{
|
|
203
|
-
const source = new sources.RawSource(llmsFullTxtContent);
|
|
204
|
-
compilation.emitAsset(name, source);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
226
|
});
|
|
208
227
|
}
|
|
209
228
|
});
|
|
@@ -305,6 +324,12 @@ function pluginLlms(options) {
|
|
|
305
324
|
const routeServiceRef = {
|
|
306
325
|
current: void 0
|
|
307
326
|
};
|
|
327
|
+
const versionsRef = {
|
|
328
|
+
current: []
|
|
329
|
+
};
|
|
330
|
+
const defaultVersionRef = {
|
|
331
|
+
current: ''
|
|
332
|
+
};
|
|
308
333
|
return {
|
|
309
334
|
name: '@rspress/plugin-llms',
|
|
310
335
|
extendPageData (pageData, isProd) {
|
|
@@ -333,6 +358,8 @@ function pluginLlms(options) {
|
|
|
333
358
|
sidebar,
|
|
334
359
|
routeServiceRef,
|
|
335
360
|
nav,
|
|
361
|
+
versionsRef,
|
|
362
|
+
defaultVersionRef,
|
|
336
363
|
baseRef,
|
|
337
364
|
disableSSGRef,
|
|
338
365
|
rspressPluginOptions: item,
|
|
@@ -347,6 +374,8 @@ function pluginLlms(options) {
|
|
|
347
374
|
sidebar,
|
|
348
375
|
routeServiceRef,
|
|
349
376
|
nav,
|
|
377
|
+
versionsRef,
|
|
378
|
+
defaultVersionRef,
|
|
350
379
|
baseRef,
|
|
351
380
|
disableSSGRef,
|
|
352
381
|
rspressPluginOptions: mergedOptions
|
|
@@ -381,6 +410,10 @@ function pluginLlms(options) {
|
|
|
381
410
|
langRef.current = config.lang ?? '';
|
|
382
411
|
baseRef.current = config.base ?? '/';
|
|
383
412
|
docDirectoryRef.current = config.root ?? 'docs';
|
|
413
|
+
if (config.multiVersion) {
|
|
414
|
+
versionsRef.current = config.multiVersion.versions || [];
|
|
415
|
+
defaultVersionRef.current = config.multiVersion.default || '';
|
|
416
|
+
}
|
|
384
417
|
}
|
|
385
418
|
};
|
|
386
419
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-llms",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A plugin for rspress to generate llms.txt, llms-full.txt, md files to let llm understand your website.",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"unist-util-visit": "^5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@microsoft/api-extractor": "^7.
|
|
39
|
-
"@rsbuild/core": "2.0.0-
|
|
40
|
-
"@rsbuild/plugin-react": "~1.4.
|
|
41
|
-
"@rslib/core": "0.19.
|
|
38
|
+
"@microsoft/api-extractor": "^7.56.0",
|
|
39
|
+
"@rsbuild/core": "2.0.0-beta.1",
|
|
40
|
+
"@rsbuild/plugin-react": "~1.4.5",
|
|
41
|
+
"@rslib/core": "0.19.4",
|
|
42
42
|
"@types/hast": "^3.0.4",
|
|
43
43
|
"@types/node": "^22.8.1",
|
|
44
44
|
"@types/react": "^19.2.10",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@rspress/config": "1.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@rspress/core": "^2.0.
|
|
52
|
+
"@rspress/core": "^2.0.2"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
|
-
"node": "
|
|
55
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public",
|