@rspress/plugin-llms 2.0.4 → 2.0.6
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 +27 -24
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -14,10 +14,11 @@ function routePathToMdPath(routePath, base) {
|
|
|
14
14
|
function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title, description, base) {
|
|
15
15
|
const lines = [];
|
|
16
16
|
const { onAfterLlmsTxtGenerate, onLineGenerate, onTitleGenerate } = llmsTxtOptions;
|
|
17
|
+
if (!onTitleGenerate && !title) logger.warn('No `title` is configured in your Rspress setup. Please set `title` in rspress.config.ts so llms.txt can include an appropriate heading.');
|
|
17
18
|
const summary = onTitleGenerate ? onTitleGenerate({
|
|
18
19
|
title,
|
|
19
20
|
description
|
|
20
|
-
}) : `# ${title}${description ? `\n\n> ${description}` : ''}
|
|
21
|
+
}) : title ? `# ${title}${description ? `\n\n> ${description}` : ''}` : '';
|
|
21
22
|
for(let i = 0; i < navList.length; i++){
|
|
22
23
|
const nav = navList[i];
|
|
23
24
|
const pages = pageDataArray[i];
|
|
@@ -43,7 +44,8 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
|
|
|
43
44
|
hasOthers = true;
|
|
44
45
|
}
|
|
45
46
|
if (hasOthers) lines.push(...otherLines);
|
|
46
|
-
|
|
47
|
+
let llmsTxt;
|
|
48
|
+
llmsTxt = summary ? lines.length > 0 ? `${summary}\n${lines.join('\n')}` : summary : lines.join('\n').trimStart();
|
|
47
49
|
return onAfterLlmsTxtGenerate ? onAfterLlmsTxtGenerate(llmsTxt) : llmsTxt;
|
|
48
50
|
}
|
|
49
51
|
function generateLlmsFullTxt(pageDataArray, navList, others, base) {
|
|
@@ -141,6 +143,25 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
|
|
|
141
143
|
const defaultVersion = defaultVersionRef.current;
|
|
142
144
|
const isMultiVersion = versions.length > 0;
|
|
143
145
|
const newPageDataList = mergeRouteMetaWithPageData(routes, pageDataList, langRef.current, include, exclude);
|
|
146
|
+
const mdContents = {};
|
|
147
|
+
await Promise.all([
|
|
148
|
+
...newPageDataList.values()
|
|
149
|
+
].map(async (pageData)=>{
|
|
150
|
+
const content = pageData._flattenContent ?? pageData.content;
|
|
151
|
+
const filepath = pageData._filepath;
|
|
152
|
+
const isMD = 'mdx' !== node_path.extname(filepath).slice(1);
|
|
153
|
+
let mdContent;
|
|
154
|
+
try {
|
|
155
|
+
mdContent = await normalizeMdFile(content, filepath, routeServiceRef.current, baseRef.current, 'boolean' != typeof mdFiles ? mdFiles?.mdxToMd ?? false : false, isMD, 'boolean' != typeof mdFiles ? mdFiles?.remarkPlugins ?? [] : []);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
logger.debug('normalizeMdFile failed', pageData.routePath, e);
|
|
158
|
+
mdContent = content;
|
|
159
|
+
}
|
|
160
|
+
const outFilePath = routePathToMdPath(pageData.routePath, '');
|
|
161
|
+
const mdContentStr = mdContent.toString();
|
|
162
|
+
mdContents[outFilePath] = mdContentStr;
|
|
163
|
+
pageData.mdContent = mdContentStr;
|
|
164
|
+
}));
|
|
144
165
|
const versionList = isMultiVersion ? versions : [
|
|
145
166
|
''
|
|
146
167
|
];
|
|
@@ -193,23 +214,6 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
|
|
|
193
214
|
});
|
|
194
215
|
}
|
|
195
216
|
}
|
|
196
|
-
const mdContents = {};
|
|
197
|
-
await Promise.all([
|
|
198
|
-
...newPageDataList.values()
|
|
199
|
-
].map(async (pageData)=>{
|
|
200
|
-
const content = pageData._flattenContent ?? pageData.content;
|
|
201
|
-
const filepath = pageData._filepath;
|
|
202
|
-
const isMD = 'mdx' !== node_path.extname(filepath).slice(1);
|
|
203
|
-
let mdContent;
|
|
204
|
-
try {
|
|
205
|
-
mdContent = await normalizeMdFile(content, filepath, routeServiceRef.current, baseRef.current, 'boolean' != typeof mdFiles ? mdFiles?.mdxToMd ?? false : false, isMD, 'boolean' != typeof mdFiles ? mdFiles?.remarkPlugins ?? [] : []);
|
|
206
|
-
} catch (e) {
|
|
207
|
-
logger.debug('normalizeMdFile failed', pageData.routePath, e);
|
|
208
|
-
mdContent = content;
|
|
209
|
-
}
|
|
210
|
-
const outFilePath = routePathToMdPath(pageData.routePath, '');
|
|
211
|
-
mdContents[outFilePath] = mdContent.toString();
|
|
212
|
-
}) ?? []);
|
|
213
217
|
if (mdFiles) api.processAssets({
|
|
214
218
|
environments: disableSSG ? [
|
|
215
219
|
'web'
|
|
@@ -266,12 +270,11 @@ function organizeBySidebar(sidebar, pages) {
|
|
|
266
270
|
const currSidebar = getSidebarDataGroup(sidebar, pageItem.routePath);
|
|
267
271
|
if (0 === currSidebar.length) return;
|
|
268
272
|
const orderList = flatSidebar(currSidebar);
|
|
273
|
+
const normalizeLink = (p)=>p.replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
269
274
|
pages.sort((a, b)=>{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
|
|
274
|
-
return aIndex - bIndex;
|
|
275
|
+
const aIndex = orderList.findIndex((order)=>matchPath(normalizeLink(order), a.routePath));
|
|
276
|
+
const bIndex = orderList.findIndex((order)=>matchPath(normalizeLink(order), b.routePath));
|
|
277
|
+
return (-1 === aIndex ? Number.MAX_SAFE_INTEGER : aIndex) - (-1 === bIndex ? Number.MAX_SAFE_INTEGER : bIndex);
|
|
275
278
|
});
|
|
276
279
|
}
|
|
277
280
|
function getDefaultOptions(lang, langs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-llms",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
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.57.
|
|
38
|
+
"@microsoft/api-extractor": "^7.57.7",
|
|
39
39
|
"@rsbuild/core": "2.0.0-beta.6",
|
|
40
40
|
"@rsbuild/plugin-react": "~1.4.5",
|
|
41
|
-
"@rslib/core": "0.
|
|
41
|
+
"@rslib/core": "0.20.0",
|
|
42
42
|
"@types/hast": "^3.0.4",
|
|
43
43
|
"@types/node": "^22.8.1",
|
|
44
44
|
"@types/react": "^19.2.14",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@rspress/config": "1.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@rspress/core": "^2.0.
|
|
52
|
+
"@rspress/core": "^2.0.6"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": "^20.19.0 || >=22.12.0"
|