Skip to content

feat(plugin-llms): init @rspress/plugin-llms #2034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 24, 2025
Merged

feat(plugin-llms): init @rspress/plugin-llms #2034

merged 6 commits into from
Apr 24, 2025

Conversation

SoonIter
Copy link
Member

@SoonIter SoonIter commented Apr 2, 2025

@rspress/plugin-llms

Generate llms.txt related files for your Rspress site, allowing large language models to better understand your documentation site.

Installation

npm add @rspress/plugin-llms -D"

Usage

Add the following configuration to your configuration file:

// rspress.config.ts
import path from 'path';
import { defineConfig } from 'rspress';
import { pluginLlms } from '@rspress/plugin-llms';

export default defineConfig({
  plugins: [pluginLlms()],
});

Then execute the rspress build command. While generating the output, the plugin will also generate llms.txt, llms.full.txt, and corresponding markdown files for each route in the output directory based on the navigation bar.

Configuration

This plugin accepts an object parameter with the following type:

export interface Options {
  llmsTxt?: boolean | LlmsTxt;
  mdFiles?: boolean;
  llmsFullTxt?: boolean;
  exclude?: (context: { page: PageIndexInfo }) => boolean;
}

llmsTxt

  • Type: boolean | LlmsTxt
import type { PageIndexInfo } from '@rspress/shared';

export interface LlmsTxt {
  onTitleGenerate?: (context: {
    title: string | undefined;
    description: string | undefined;
  }) => string;
  onLineGenerate?: (page: PageIndexInfo) => string;
  onAfterLlmsTxtGenerate?: (llmsTxtContent: string) => string;
}
  • Default: true

Whether to generate the llms.txt file, or to customize the llms.txt file through hooks.

The default format of an llms.txt file is as follows:

# {title}

> {description}

## {nav1.title}

- [{page.title}]({ page.routePath }): {page.frontmatter.description}

## {nav2.title}

- [{page.title}]({ page.routePath }): {page.frontmatter.description}

You can modify the specified part through hook.

  • onTitleGenerate: Customize the generated title and description sections.
  • onLineGenerate: Customize each line of the md file.
  • onAfterLlmsTxtGenerate: Finally modify the contents of the llms.txt file.

For example:

pluginLlms({
  llmsTxt: {
    onTitleGenerate: ({ title, description }) => {
      return `# ${title} - llms.txt

> ${description}

Rspress is a static site generator based on Rsbuild and it can generate llms.txt with @rspress/plugin-llms.
`;
    },
  },
});

The corresponding generation results are:

# Rspress - llms.txt

> Rsbuild based static site generator

Rspress is a static site generator based on Rsbuild and it can generate llms.txt with @rspress/plugin-llms.

## guide

- [foo](/foo.md)

mdFiles

  • Type: boolean
  • Default: true

Whether to generate a markdown file for the corresponding route, when set to false, the markdown file for the corresponding route will not be generated.

llmsFullTxt

  • Type: boolean
  • Default: true

Whether to generate the llms.full.txt file, the llms.full.txt file will not be generated when set to false.

exclude

  • Type: (context: { page: PageIndexInfo }) => boolean
  • Default: undefined

Whether to exclude certain routes when generating, it is generally used to streamline llms.txt.

  • Example:
pluginLlms({
  exclude: ({ page }) => {
    return page.routePath.includes('foo');
  },
});

Related Issue

close #1973

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Apr 2, 2025

Deploy Preview for rspress ready!

Name Link
🔨 Latest commit f9bf760
🔍 Latest deploy log https://app.netlify.com/sites/rspress/deploys/6809ad5988b1e70008fa62cf
😎 Deploy Preview https://deploy-preview-2034--rspress.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 74 (🔴 down 12 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (🟢 up 9 from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 2, 2025

Deploy Preview for rspress-v2 ready!

Name Link
🔨 Latest commit f9bf760
🔍 Latest deploy log https://app.netlify.com/sites/rspress-v2/deploys/6809ad59562569000891ac2e
😎 Deploy Preview https://deploy-preview-2034--rspress-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@SoonIter SoonIter changed the title feat(plugin-llm): init @rspress/plugin-llm feat(plugin-llm): init @rspress/plugin-llms Apr 3, 2025
@SoonIter SoonIter force-pushed the rspress-llm branch 2 times, most recently from b6aedbf to b85cd9b Compare April 9, 2025 10:14
@SoonIter SoonIter force-pushed the rspress-llm branch 2 times, most recently from 0d39171 to 1491ecc Compare April 15, 2025 12:13
@SoonIter SoonIter force-pushed the rspress-llm branch 6 times, most recently from df1ff37 to 476eb29 Compare April 23, 2025 07:28
@Timeless0911 Timeless0911 changed the title feat(plugin-llm): init @rspress/plugin-llms feat(plugin-llms): init @rspress/plugin-llms Apr 23, 2025
@SoonIter SoonIter merged commit d53fd6b into main Apr 24, 2025
11 checks passed
@SoonIter SoonIter deleted the rspress-llm branch April 24, 2025 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support plugin-llms-txt
2 participants