@rspress/plugin-llms 2.0.16 → 2.0.18

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.
Files changed (2) hide show
  1. package/dist/index.js +20 -12
  2. package/package.json +6 -5
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import node_path from "node:path";
2
- import { getSidebarDataGroup, logger, matchPath, normalizeHref, remarkFileCodeBlock, remarkLink, withBase } from "@rspress/core";
2
+ import { getSidebarDataGroup, logger, matchPath, normalizeHref, remarkFileCodeBlock, remarkLink, withBase, withSiteOrigin } from "@rspress/core";
3
3
  import remark_mdx from "remark-mdx";
4
4
  import remark_parse from "remark-parse";
5
5
  import remark_stringify from "remark-stringify";
6
6
  import { unified } from "unified";
7
7
  import { SKIP, visit } from "unist-util-visit";
8
- function routePathToMdPath(routePath, base) {
8
+ function routePathToMdPath(routePath, base, siteOrigin) {
9
9
  let url = routePath;
10
10
  url = normalizeHref(url, false);
11
11
  url = url.replace(/\.html$/, '.md');
12
- return withBase(url, base);
12
+ return withSiteOrigin(withBase(url, base), siteOrigin);
13
13
  }
14
- function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title, description, base) {
14
+ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title, description, base, siteOrigin) {
15
15
  const lines = [];
16
16
  const { onAfterLlmsTxtGenerate, onLineGenerate, onTitleGenerate } = llmsTxtOptions;
17
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.');
@@ -29,7 +29,7 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
29
29
  for (const page of pages){
30
30
  const { routePath, lang, title, description } = page;
31
31
  if ('/' === routePath || routePath === `/${lang}/`) continue;
32
- const line = onLineGenerate ? onLineGenerate(page) : `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
32
+ const line = onLineGenerate ? onLineGenerate(page) : `- [${title}](${routePathToMdPath(routePath, base, siteOrigin)})${description ? `: ${description}` : ''}`;
33
33
  lines.push(line);
34
34
  }
35
35
  }
@@ -39,7 +39,7 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
39
39
  for (const page of others){
40
40
  const { routePath, lang, title, description } = page;
41
41
  if ('/' === routePath || routePath === `/${lang}/`) continue;
42
- const line = onLineGenerate ? onLineGenerate(page) : `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
42
+ const line = onLineGenerate ? onLineGenerate(page) : `- [${title}](${routePathToMdPath(routePath, base, siteOrigin)})${description ? `: ${description}` : ''}`;
43
43
  otherLines.push(line);
44
44
  hasOthers = true;
45
45
  }
@@ -48,13 +48,13 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
48
48
  llmsTxt = summary ? lines.length > 0 ? `${summary}\n${lines.join('\n')}` : summary : lines.join('\n').trimStart();
49
49
  return onAfterLlmsTxtGenerate ? onAfterLlmsTxtGenerate(llmsTxt) : llmsTxt;
50
50
  }
51
- function generateLlmsFullTxt(pageDataArray, navList, others, base) {
51
+ function generateLlmsFullTxt(pageDataArray, navList, others, base, siteOrigin) {
52
52
  const lines = [];
53
53
  for(let i = 0; i < navList.length; i++){
54
54
  const pages = pageDataArray[i];
55
55
  if (0 !== pages.length) for (const page of pages){
56
56
  lines.push(`---
57
- url: ${routePathToMdPath(page.routePath, base)}
57
+ url: ${routePathToMdPath(page.routePath, base, siteOrigin)}
58
58
  ---
59
59
  `);
60
60
  lines.push(page.mdContent ?? page._flattenContent ?? page.content);
@@ -63,7 +63,7 @@ url: ${routePathToMdPath(page.routePath, base)}
63
63
  }
64
64
  for (const page of others){
65
65
  lines.push(`---
66
- url: ${routePathToMdPath(page.routePath, base)}
66
+ url: ${routePathToMdPath(page.routePath, base, siteOrigin)}
67
67
  ---
68
68
  `);
69
69
  lines.push(page.mdContent ?? page._flattenContent ?? page.content);
@@ -128,7 +128,7 @@ function resolveNavForVersion(nav, version, defaultVersion) {
128
128
  }));
129
129
  }).filter((i)=>i.activeMatch || i.link);
130
130
  }
131
- const rsbuildPluginLlms = ({ docDirectory, disableSSGRef, baseRef, pageDataList, routes, titleRef, descriptionRef, langRef, sidebar, routeServiceRef, nav, versionsRef, defaultVersionRef, rspressPluginOptions, index = 0 })=>({
131
+ const rsbuildPluginLlms = ({ docDirectory, disableSSGRef, baseRef, pageDataList, routes, titleRef, descriptionRef, langRef, siteOriginRef, sidebar, routeServiceRef, nav, versionsRef, defaultVersionRef, rspressPluginOptions, index = 0 })=>({
132
132
  name: `rsbuild-plugin-llms-${index}`,
133
133
  async setup (api) {
134
134
  const { llmsTxt = {
@@ -187,7 +187,7 @@ const rsbuildPluginLlms = ({ docDirectory, disableSSGRef, baseRef, pageDataList,
187
187
  const versionPrefix = isMultiVersion && version !== defaultVersion ? `${version}/` : '';
188
188
  if (llmsTxt) {
189
189
  const name = `${versionPrefix}${llmsTxt.name}`;
190
- const llmsTxtContent = generateLlmsTxt(pageArray, navList, others, llmsTxt, titleRef.current, descriptionRef.current, baseRef.current);
190
+ const llmsTxtContent = generateLlmsTxt(pageArray, navList, others, llmsTxt, titleRef.current, descriptionRef.current, baseRef.current, siteOriginRef.current);
191
191
  api.processAssets({
192
192
  environments: disableSSG ? [
193
193
  'web'
@@ -202,7 +202,7 @@ const rsbuildPluginLlms = ({ docDirectory, disableSSGRef, baseRef, pageDataList,
202
202
  }
203
203
  if (llmsFullTxt) {
204
204
  const name = `${versionPrefix}${llmsFullTxt.name}`;
205
- const llmsFullTxtContent = generateLlmsFullTxt(pageArray, navList, others, baseRef.current);
205
+ const llmsFullTxtContent = generateLlmsFullTxt(pageArray, navList, others, baseRef.current, siteOriginRef.current);
206
206
  api.processAssets({
207
207
  targets: disableSSG ? [
208
208
  'web'
@@ -319,6 +319,9 @@ function pluginLlms(options) {
319
319
  const langRef = {
320
320
  current: ''
321
321
  };
322
+ const siteOriginRef = {
323
+ current: ''
324
+ };
322
325
  const pageDataList = [];
323
326
  const routes = [];
324
327
  const sidebar = {};
@@ -355,6 +358,8 @@ function pluginLlms(options) {
355
358
  if (!config.builderConfig) config.builderConfig = {};
356
359
  if (!config.builderConfig.plugins) config.builderConfig.plugins = [];
357
360
  const docDirectory = config.root;
361
+ baseRef.current = config.base ?? '/';
362
+ siteOriginRef.current = config.siteOrigin;
358
363
  config.builderConfig.plugins.push(...Array.isArray(mergedOptions) ? mergedOptions.map((item, index)=>rsbuildPluginLlms({
359
364
  docDirectory,
360
365
  pageDataList,
@@ -362,6 +367,7 @@ function pluginLlms(options) {
362
367
  titleRef,
363
368
  descriptionRef,
364
369
  langRef,
370
+ siteOriginRef,
365
371
  sidebar,
366
372
  routeServiceRef,
367
373
  nav,
@@ -379,6 +385,7 @@ function pluginLlms(options) {
379
385
  titleRef,
380
386
  descriptionRef,
381
387
  langRef,
388
+ siteOriginRef,
382
389
  sidebar,
383
390
  routeServiceRef,
384
391
  nav,
@@ -416,6 +423,7 @@ function pluginLlms(options) {
416
423
  titleRef.current = config.title;
417
424
  descriptionRef.current = config.description;
418
425
  langRef.current = config.lang ?? '';
426
+ siteOriginRef.current = config.siteOrigin;
419
427
  baseRef.current = config.base ?? '/';
420
428
  docDirectoryRef.current = config.root ?? 'docs';
421
429
  if (config.multiVersion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-llms",
3
- "version": "2.0.16",
3
+ "version": "2.0.18",
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": {
@@ -36,10 +36,11 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@microsoft/api-extractor": "^7.58.9",
39
- "@rsbuild/core": "^2.0.15",
40
- "@rsbuild/plugin-react": "~2.0.1",
41
- "@rslib/core": "0.23.0",
42
- "@types/hast": "^3.0.4",
39
+ "@rsbuild/core": "^2.1.5",
40
+ "@rsbuild/plugin-react": "~2.1.0",
41
+ "@rslib/core": "0.23.2",
42
+ "@types/hast": "^3.0.5",
43
+ "@types/mdast": "^4.0.4",
43
44
  "@types/node": "^22.8.1",
44
45
  "@types/react": "^19.2.17",
45
46
  "react": "^19.2.7",