@rspress/plugin-llms 2.0.0-beta.1 → 2.0.0-beta.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.d.ts CHANGED
@@ -355,12 +355,21 @@ export declare interface Options {
355
355
  */
356
356
  mdFiles?: boolean;
357
357
  /**
358
- * Whether to generate llms.full.txt.
358
+ * Whether to generate llms-full.txt.
359
359
  * @default true
360
360
  */
361
361
  llmsFullTxt?: boolean;
362
+ /**
363
+ * Whether to include some routes from llms.txt.
364
+ * @param context
365
+ * @default (context) => context.page.lang === config.lang
366
+ */
367
+ include?: (context: {
368
+ page: PageIndexInfo;
369
+ }) => boolean;
362
370
  /**
363
371
  * Whether to exclude some routes from llms.txt.
372
+ * exclude will trigger after include
364
373
  * @default undefined
365
374
  */
366
375
  exclude?: (context: {
package/dist/index.js CHANGED
@@ -5904,7 +5904,7 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
5904
5904
  }
5905
5905
  let hasOthers = false;
5906
5906
  const otherLines = [];
5907
- otherLines.push('\n## Others\n');
5907
+ otherLines.push('\n## Other\n');
5908
5908
  for (const page of others){
5909
5909
  const { routePath, lang, title, frontmatter } = page;
5910
5910
  if ('/' === routePath || routePath === `/${lang}/`) continue;
@@ -5919,18 +5919,21 @@ function generateLlmsTxt(pageDataArray, navList, others, llmsTxtOptions, title,
5919
5919
  function generateLlmsFullTxt(pageDataArray, navList, others) {
5920
5920
  const lines = [];
5921
5921
  for(let i = 0; i < navList.length; i++){
5922
- const nav = navList[i];
5923
5922
  const pages = pageDataArray[i];
5924
- if (0 === pages.length) continue;
5925
- const title = nav.text;
5926
- lines.push(`# ${title}\n`);
5927
- for (const page of pages){
5923
+ if (0 !== pages.length) for (const page of pages){
5924
+ lines.push(`---
5925
+ url: ${routePathToMdPath(page.routePath)}
5926
+ ---
5927
+ `);
5928
5928
  lines.push(page.mdContent ?? page._flattenContent ?? page.content);
5929
5929
  lines.push('\n');
5930
5930
  }
5931
5931
  }
5932
- lines.push('# Others\n');
5933
5932
  for (const page of others){
5933
+ lines.push(`---
5934
+ url: ${routePathToMdPath(page.routePath)}
5935
+ ---
5936
+ `);
5934
5937
  lines.push(page.mdContent ?? page._flattenContent ?? page.content);
5935
5938
  lines.push('\n');
5936
5939
  }
@@ -20903,14 +20906,14 @@ function mdxToMd(content, filepath, docDirectory, routeService) {
20903
20906
  path: filepath
20904
20907
  });
20905
20908
  }
20906
- const rsbuildPluginLlms = ({ pageDataList, routes, titleRef, descriptionRef, sidebar, baseRef, docDirectoryRef, routeServiceRef, nav, rspressPluginOptions })=>({
20909
+ const rsbuildPluginLlms = ({ pageDataList, routes, titleRef, descriptionRef, langRef, sidebar, baseRef, docDirectoryRef, routeServiceRef, nav, rspressPluginOptions })=>({
20907
20910
  name: 'rsbuild-plugin-llms',
20908
20911
  async setup (api) {
20909
- const { llmsTxt = true, mdFiles = true, llmsFullTxt = true, exclude } = rspressPluginOptions;
20912
+ const { llmsTxt = true, mdFiles = true, llmsFullTxt = true, include, exclude } = rspressPluginOptions;
20910
20913
  api.onBeforeBuild(async ()=>{
20911
20914
  const base = baseRef.current;
20912
20915
  const docDirectory = docDirectoryRef.current;
20913
- const newPageDataList = mergeRouteMetaWithPageData(routes, pageDataList, exclude);
20916
+ const newPageDataList = mergeRouteMetaWithPageData(routes, pageDataList, langRef.current, include, exclude);
20914
20917
  const navList = Array.isArray(nav) ? nav.map((i)=>{
20915
20918
  const nav = i.nav.default;
20916
20919
  const lang = i.lang;
@@ -20983,15 +20986,21 @@ const rsbuildPluginLlms = ({ pageDataList, routes, titleRef, descriptionRef, sid
20983
20986
  stage: 'additional'
20984
20987
  }, async ({ compilation, sources })=>{
20985
20988
  const source = new sources.RawSource(llmsFullTxtContent);
20986
- compilation.emitAsset('llms.full.txt', source);
20989
+ compilation.emitAsset('llms-full.txt', source);
20987
20990
  });
20988
20991
  }
20989
20992
  });
20990
20993
  }
20991
20994
  });
20992
- function mergeRouteMetaWithPageData(routeMetaList, pageDataList, exclude) {
20995
+ function mergeRouteMetaWithPageData(routeMetaList, pageDataList, lang, include, exclude) {
20993
20996
  const m = new Map(pageDataList.filter((pageData)=>{
20994
- if (exclude) return !exclude?.({
20997
+ if (include) return include({
20998
+ page: pageData
20999
+ });
21000
+ if (lang) return pageData.lang === lang;
21001
+ return true;
21002
+ }).filter((pageData)=>{
21003
+ if (exclude) return !exclude({
20995
21004
  page: pageData
20996
21005
  });
20997
21006
  return true;
@@ -21042,6 +21051,9 @@ function pluginLlms(options = {}) {
21042
21051
  const descriptionRef = {
21043
21052
  current: ''
21044
21053
  };
21054
+ const langRef = {
21055
+ current: ''
21056
+ };
21045
21057
  const pageDataList = [];
21046
21058
  const routes = [];
21047
21059
  const sidebar = {};
@@ -21073,6 +21085,7 @@ function pluginLlms(options = {}) {
21073
21085
  nav.push(...configNav);
21074
21086
  titleRef.current = config.title;
21075
21087
  descriptionRef.current = config.description;
21088
+ langRef.current = config.lang;
21076
21089
  baseRef.current = config.base ?? '/';
21077
21090
  docDirectoryRef.current = config.root ?? 'docs';
21078
21091
  },
@@ -21084,6 +21097,7 @@ function pluginLlms(options = {}) {
21084
21097
  routes,
21085
21098
  titleRef,
21086
21099
  descriptionRef,
21100
+ langRef,
21087
21101
  sidebar,
21088
21102
  docDirectoryRef,
21089
21103
  routeServiceRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-llms",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.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": {
@@ -34,11 +34,11 @@
34
34
  "typescript": "^5.8.2",
35
35
  "vfile": "^6.0.3",
36
36
  "@rspress/config": "1.0.0",
37
- "@rspress/shared": "2.0.0-beta.1"
37
+ "@rspress/shared": "2.0.0-beta.2"
38
38
  },
39
39
  "peerDependencies": {
40
- "@rspress/core": "^2.0.0-beta.1",
41
- "@rspress/runtime": "^2.0.0-beta.1"
40
+ "@rspress/core": "^2.0.0-beta.2",
41
+ "@rspress/runtime": "^2.0.0-beta.2"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.0.0"