@rspress/plugin-llms 2.0.0-beta.28 → 2.0.0-beta.29

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { PageIndexInfo } from '@rspress/core';
2
+ import type { PluggableList } from 'unified';
2
3
  import type { RspressPlugin } from '@rspress/core';
3
4
 
4
5
  /**
@@ -23,9 +24,15 @@ export declare interface LlmsTxt {
23
24
 
24
25
  declare interface MdFiles {
25
26
  /**
27
+ * Whether to convert mdx to md.
26
28
  * @default false
27
29
  */
28
- mdxToMd: boolean;
30
+ mdxToMd?: boolean;
31
+ /**
32
+ * Allow users to customize remarkPlugins and edit the content of generated md files.
33
+ * @default []
34
+ */
35
+ remarkPlugins?: PluggableList;
29
36
  }
30
37
 
31
38
  export declare interface Options {
@@ -43,8 +50,7 @@ export declare interface Options {
43
50
  llmsFullTxt?: false | LlmsFullTxt;
44
51
  /**
45
52
  * Whether to include some routes from llms.txt.
46
- * @param context
47
- * @default (context) => context.page.lang === config.lang
53
+ * @default undefined
48
54
  */
49
55
  include?: (context: {
50
56
  page: PageIndexInfo;
package/dist/index.js CHANGED
@@ -90,8 +90,8 @@ const mdxToMdPlugin = ()=>(tree)=>{
90
90
  });
91
91
  };
92
92
  function noopPlugin() {}
93
- function normalizeMdFile(content, filepath, routeService, base, mdxToMd, isMd) {
94
- return unified().use(remark_parse).use(isMd ? noopPlugin : remark_mdx).use(remarkFileCodeBlock, {
93
+ function normalizeMdFile(content, filepath, routeService, base, mdxToMd, isMd, remarkPlugins) {
94
+ const compiler = unified().use(remark_parse).use(isMd ? noopPlugin : remark_mdx).use(remarkFileCodeBlock, {
95
95
  filepath
96
96
  }).use(!isMd && mdxToMd ? mdxToMdPlugin : noopPlugin).use(remarkLink, {
97
97
  cleanUrls: '.md',
@@ -101,7 +101,8 @@ function normalizeMdFile(content, filepath, routeService, base, mdxToMd, isMd) {
101
101
  autoPrefix: true
102
102
  },
103
103
  __base: base
104
- }).use(remark_stringify).process({
104
+ }).use(remarkPlugins).use(remark_stringify);
105
+ return compiler.process({
105
106
  value: content,
106
107
  path: filepath
107
108
  });
@@ -112,7 +113,8 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
112
113
  const { llmsTxt = {
113
114
  name: 'llms.txt'
114
115
  }, mdFiles = {
115
- mdxToMd: false
116
+ mdxToMd: false,
117
+ remarkPlugins: []
116
118
  }, llmsFullTxt = {
117
119
  name: 'llms-full.txt'
118
120
  }, include, exclude } = rspressPluginOptions;
@@ -163,7 +165,7 @@ const rsbuildPluginLlms = ({ disableSSGRef, baseRef, pageDataList, routes, title
163
165
  const isMD = 'mdx' !== node_path.extname(filepath).slice(1);
164
166
  let mdContent;
165
167
  try {
166
- mdContent = (await normalizeMdFile(content, filepath, routeServiceRef.current, baseRef.current, 'boolean' != typeof mdFiles ? mdFiles?.mdxToMd : false, isMD)).toString();
168
+ mdContent = (await normalizeMdFile(content, filepath, routeServiceRef.current, baseRef.current, 'boolean' != typeof mdFiles ? mdFiles?.mdxToMd ?? false : false, isMD, 'boolean' != typeof mdFiles ? mdFiles?.remarkPlugins ?? [] : [])).toString();
167
169
  } catch (e) {
168
170
  logger.debug('normalizeMdFile failed', pageData.routePath, e);
169
171
  mdContent = content;
@@ -243,8 +245,10 @@ function organizeBySidebar(sidebar, pages) {
243
245
  if (0 === currSidebar.length) return;
244
246
  const orderList = flatSidebar(currSidebar);
245
247
  pages.sort((a, b)=>{
246
- const aIndex = orderList.findIndex((order)=>matchPath(order, a.routePath));
247
- const bIndex = orderList.findIndex((order)=>matchPath(order, b.routePath));
248
+ let aIndex = orderList.findIndex((order)=>matchPath(order, a.routePath));
249
+ if (-1 === aIndex) aIndex = Number.MAX_SAFE_INTEGER;
250
+ let bIndex = orderList.findIndex((order)=>matchPath(order, b.routePath));
251
+ if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
248
252
  return aIndex - bIndex;
249
253
  });
250
254
  }
@@ -257,9 +261,6 @@ function getDefaultOptions(lang, langs) {
257
261
  },
258
262
  llmsFullTxt: {
259
263
  name: 'llms-full.txt'
260
- },
261
- include ({ page }) {
262
- return page.lang === l;
263
264
  }
264
265
  };
265
266
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-llms",
3
- "version": "2.0.0-beta.28",
3
+ "version": "2.0.0-beta.29",
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,14 +35,14 @@
35
35
  "unist-util-visit": "^5.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@microsoft/api-extractor": "^7.52.10",
39
- "@rsbuild/core": "~1.4.15",
38
+ "@microsoft/api-extractor": "^7.52.11",
39
+ "@rsbuild/core": "~1.4.16",
40
40
  "@rsbuild/plugin-react": "~1.3.5",
41
41
  "@rsbuild/plugin-sass": "~1.3.5",
42
- "@rslib/core": "0.12.1",
42
+ "@rslib/core": "0.12.2",
43
43
  "@types/hast": "^3.0.4",
44
44
  "@types/node": "^22.8.1",
45
- "@types/react": "^19.1.10",
45
+ "@types/react": "^19.1.11",
46
46
  "react": "^19.1.1",
47
47
  "rsbuild-plugin-publint": "^0.3.3",
48
48
  "typescript": "^5.8.2",
@@ -50,7 +50,7 @@
50
50
  "@rspress/config": "1.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@rspress/core": "^2.0.0-beta.28"
53
+ "@rspress/core": "^2.0.0-beta.29"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=18.0.0"