Skip to content

New Docusaurus plugin: docusaurus-plugin-llms-txt #10899

Open

Description

@jharrell

Have you read the Contributing Guidelines on issues?

Description

Hello!

I'd like to propose the creation of a new docusaurus plugin for the creation of a llms.txt file.

As background, an llms.txt file is a way of co-locating needed information such that an LLM processing web pages is able to do so effectively and quickly. More information can be found on the llms.txt proposal website

The goal of this feature is to create a plugin that will generate this file for your docs.

Has this been requested on Canny?

No

Motivation

Having an llms.txt is a business need for our company, but I'm certain it would be helpful for others. I have already created a proof-of-concept plugin that writes the file, but I wanted to bring this to the community as a whole to see how the design could be improved and/or match others' use cases.

Additionally, many docs sites that I use and admire, such as dub.co and Cloudflare have already implemented llms.txt files. The former via Mintlify, the latter via a script.

Adding a new, optional plugin would give Docusaurus users the ability to opt-in to this new standard and allow their documentation to be accessed easily by LLM agents.

API design

The design is very similar to the sitemap plugin.

Configuration

  • ignorePatterns: ability to ignore specific paths from being included in the llms.txt.
  • filename: ability to change the name and output path of the llms.txt file.

I also considered configuration modifying the output of the file, but the llms.txt proposal is fairly set on the file structure so I declined to add that as a configuration option.

Have you tried building it?

Yes! I made a simple plugin that works for our use case. I would like to move it into this repo in order to make it available to other folks and to get feedback on the design. I feel it could be made much simpler and cleaner 😄

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.

Activity

  1. added
    feature
    status: needs triage
    on Feb 4, 2025
  2. slorber commented on Feb 6, 2025

    @slorber
    Collaborator

    We usually add to the Docusaurus core repo what we use on our own website. In this case it's not really a need we have, and adding this to core would put the burden on us to maintain over the long term. Many people want to add their plugin to core but we can't do that otherwise we'd end up with too many packages to maintain. I'd prefer to keep a lean core and keep this plugin in the community.


    Also, I'm really not sure what this plugin adds to the regular sitemap.xml file.

    I've checked your POC (prisma/web#6645), and as far as I understand it basically creates a list of links in Markdown format, but using a .txt extension instead of Markdown (why not use llmt.md? 🤷‍♂ )

    Result: https://jharrell-llms-plugin.docs-51g.pages.dev/llms.txt

    If we look at the Cloudflare example, it's also a list of links in Markdown format.
    https://developers.cloudflare.com/llms.txt

    I'm not sure how the h2 headings and occasional labels bring a lot of value to a regular sitemap.

    Also your site recommends to link to html.md files, which you don't do here so the LLM would have to read an HTML page anyway. And we use MDX which means that this format is already less "LLM-friendly" that regular Markdown files which cannot contain React components that must be evaluated.

    This site is linking to Markdown files, for example: https://docs.fastht.ml/llms.txt


    This field is not my expertise but I don't find this proposal super convincing, it looks more like an early draft not covering edge cases than a spec. I don't think it should be added to Docusaurus core until the proposal gets more mainstream adoption and gets better documented. I'd also prefer if there was first a community implementation that satisfies early adopters. We can consider adding this to our repo later, but not as a first step. Until then I'm happy to support you developing a community plugin, so let me know if you are unable to achieve your needs.

    I also wonder why it has to be a Docusaurus plugin. You could build a generic CLI tool that handles a full generic static deployment, looking for sitemap.xml or HTML files and creating LLM-friendly content.

  3. removed
    status: needs triage
    on Feb 6, 2025
  4. jharrell commented on Feb 6, 2025

    @jharrell
    Author

    Thank you @slorber for the context. I don't disagree with your assessment, so I'll be closing this proposal.

    For further information about why this over a sitemap etc there's this section of the proposed standard: https://llmstxt.org/#existing-standards

    Thank you for the feedback, though. I'll continue to use my simplified solution.

  5. DenhamPreen commented on Feb 19, 2025

    @DenhamPreen

    @jharrell could you share your "simplified solution", this does sound useful :)

  6. jharrell commented on Feb 19, 2025

    @jharrell
    Author

    @DenhamPreen sure. We're still iterating but here's the latest: https://github.com/prisma/docs/blob/22208d52e4168028dbbe8b020b10682e6b526e50/docusaurus.config.ts#L95

    It generates an llms-full.txt and llms.txt.

    Happy to chat further about it if I can help, my bsky account is in my GitHub profile 😊

  7. added a commit that references this issue on Apr 28, 2025
  8. slorber commented on May 23, 2025

    @slorber
    Collaborator

    Considering the number of issues linking back to this one, I think we should consider implementing such a plugin in Docusaurus core, even though I'm still not super convinced by the usefulness of this file.

    See some ideas on how this can be implemented here: #11191 (comment)

    Note: many have copied the Prisma implementation, which works, but IMHO it's not ideal. We only generate llms.txt in prod builds, so it's preferable to read the dirs and md source files there instead of inside loadContent() (which is more useful in dev to support hot reload).

  9. slorber commented on May 23, 2025

    @slorber
    Collaborator

    Plugin design?

    In my opinion, the problems we have when generating such llms file are:

    • which routes/source files should be listed
    • how to group routes together under Markdown headings of various levels
    • how do we order the headings
    • how do we order the links within each group

    We already exposed some metadata in the postBuild({routes, routesBuildMetadata}) attributes.

    export default function pluginLlms(
      context: LoadContext,
      options: PluginOptions,
    ): Plugin<void> | null {
      return {
        name: 'docusaurus-plugin-llms',
        async postBuild({routes, routesBuildMetadata}) {
          const finalRoutes = flattenRoutes(routes);
          finalRoutes.forEach((route) => {
            if (route.metadata?.sourceFilePath) {
              console.log(
                `Route ${route.path} was created from markdown file ${route.metadata?.sourceFilePath}`,
              );
            }
          });
        },
      };
    }

    We could easily enrich these with extra metadata that could be useful to generate the llms files (title, breadcrumb, other metadata).

    Now, I'm not sure what kind of API the plugin could expose to define how Markdown files are grouped, and how we define an explicit order (does it even matter to LLMs?).

    I guess we could provide a callback so that you can define the Markdown breadcrumb for each file, but that wouldn't allow you to order things:

    ['llms-plugin',{
      getMarkdownBreadcrumb: ({title, sourceFilePath}) => {
        if (isBlog(sourceFilePath)) {
          return ["Blog"];
        }
        if (isiOSDocs(sourceFilePath)) {
          return ["Docs","iOS"];
        }
        if (isAndroidDocs(sourceFilePath)) {
          return ["Docs", "Android"];
        }
        return null;
      }
    }]

    Does it make sense?


    It could be useful if the community provided concrete examples. Given a specific sample site, what kind of LLMS file do you expect it to output, and why?

    The more diverse examples we have, the easier it becomes to design an API that suits all needs.

  10. rachfop commented on May 23, 2025

    @rachfop
  11. Devon-White commented on May 23, 2025

    @Devon-White

    I also started working on our own version of the plugin: signalwire/docs#290

    I tried to mimic the behavior 1:1 with stripe where it also generates a .md version of every doc in the same route. So most routes you can append just .md and get the raw version of the doc.

    I also opted to do a postBuild action and converted the rendered HTML back to markdown. My decision to do this was because I didn't want to deal with components and partials in the initial content.

    I also added some built in rehype plugins to handle certain edge-cases that are known (like list in tables), and updating links to match the URL options that are set in the config (relative path, full URL, markdown generated doc)

    I tried to make it as flexible as possible to work with any current Docusaurus website via the contentSelectors property.

    Example preview can be seen here: https://deploy-preview-290--signalwire-docs.netlify.app/llms.txt

    Because its not pushed to our main site yet (also haven't implemented validate URL logic yet) don't use the full URLs, but just the relative portion (e.g: dont use https://example/com/ai.md use /ai.md

  12. spaansba commented on Jun 5, 2025

    @spaansba

    I think an official LLMs.txt plugin would be great. Here's how I believe it should work:

    Proposed Build Process

    1. llms.txt Generation

    • Scan all content directories (/docs, /blog, etc.) for .md files
    • Generate a hierarchical tree structure based on file paths and frontmatter metadata (see Vercel llms.txt)
    • Use frontmatter description field or a new llms_description metadata attribute for page descriptions
    • The llms.txt files should be located at the root of the content. So /docs/llms.txt, /blog/llms.txt

    2. Raw Markdown File Generation

    The llms.txt standard recommend providing an .md for every page which the main llms.txt can link to.

    • All .md pages need a cleaned markdown file with frontmatter and jsx stripped at {page-url}.md
    • Example: /docs/integrations/react → /docs/integrations/react.md
    • Maintain internal links but convert them to reference other .md files (if that is even possible)

    3. llms-full.txt Generation

    • With all .md files from 2. combined create a llms-full.txt file also at the root of the content. So /docs/llms.txt, /blog/llms.txt

    I would be happy to give it a shot.

  13. Devon-White commented on Jun 5, 2025

    @Devon-White

    I think an official LLMs.txt plugin would be great. Here's how I believe it should work:

    Proposed Build Process

    1. llms.txt Generation

    • Scan all content directories (/docs, /blog, etc.) for .md files
    • Generate a hierarchical tree structure based on file paths and frontmatter metadata (see Vercel llms.txt)
    • Use frontmatter description field or a new llms_description metadata attribute for page descriptions
    • The llms.txt files should be located at the root of the content. So /docs/llms.txt, /blog/llms.txt

    2. Raw Markdown File Generation

    The llms.txt standard recommend providing an .md for every page which the main llms.txt can link to.

    • All .md pages need a cleaned markdown file with frontmatter and jsx stripped at {page-url}.md
    • Example: /docs/integrations/react → /docs/integrations/react.md
    • Maintain internal links but convert them to reference other .md files (if that is even possible)

    3. llms-full.txt Generation

    • With all .md files from 2. combined create a llms-full.txt file also at the root of the content. So /docs/llms.txt, /blog/llms.txt

    I would be happy to give it a shot.

    You may want to take a look at the plugin we just created, as it does a lot of what your looking for (link conversion, md file generation, ability to pass your own remark & rehype plugins to alter the generation, etc..)

    The big difference for our approach is we work with the routes that are passed to us during the postBuild cycle. We then use unified to help find the html file and convert it back to markdown. My decision to convert the rendered HTML back to markdown is to handle MDX partials and React components. Content may not be displayed properly since they are not rendered yet.

    I think the only things we don't currently have you are looking for is

    1. A llms-full.txt generation option
    2. The ability to overwrite the description for a page(route).

    With how the code is made, both of these options would be easy to add.

    Feel free to open any feature request or issues at: https://github.com/signalwire/docusaurus-plugins

  14. Tobbe commented on Jun 9, 2025

    @Tobbe
  15. peterpeterparker commented on Jul 2, 2025

    @peterpeterparker

    Joining the party as well and sharing this in case it’s useful to anyone: I also followed the path of creating a custom plugin to generate /llms.txt and /llms-full.txt, tailored to my needs for Juno.

    Note: I'm not an AI expert at all, more a real noob.

    I may have taken a different approach by actually retro-engineering the Markdown files from the generated HTML files - i.e., once the site is generated, I filter the files to build a tree of the information I consider important for the language model, and then generate a Markdown file for each of those HTML files using Turndown. In addition, I also use JSDOM to extract the title and description for each of those links.

    Worth noting: when I generate the Markdown files, I also manipulate the links to construct a navigation structure related to those files - i.e., Markdown files link to other Markdown files, not to the original HTML.

    The solution definitely needs more iteration, and it’s not my most brilliant work - I left performance considerations aside and haven’t written any tests yet 😅 - but it’s a start.

    I scoped all the logic and functions into a single module.

    You can find the plugin here 👉 https://github.com/junobuild/docs/blob/main/plugins/docusaurus.llms.plugin.ts

  16. slorber commented on Jul 2, 2025

    @slorber
    Collaborator

    Interesting blog post from a Sentry engineer implementing llms.txt: https://byk.im/posts/marking-it-up-and-down/

    Since we cannot go directly from MDX to Markdown, we had to render the HTML from MDX first and then convert it to Markdown, essentially doubling the work.

  17. peterpeterparker commented on Jul 7, 2025

    @peterpeterparker

    So, in addition to the custom plugin I shared above, I’ve added a CI job that snapshots the generated llms.txt files and commits any changes with the PR. It slows down a bit, but this way I can review the diff and make sure the LLMs still look good. No formal tests but, some sort of assertions. Long story short: if that could be useful to anyone in addition to the plugin too, here you go 👉 https://github.com/junobuild/docs/blob/main/.github/workflows/llms.yml

  18. nicolasiscoding commented on Jul 22, 2025

    @nicolasiscoding

    where did we end up with this?

  19. Devon-White commented on Oct 4, 2025

    @Devon-White

    Additionally, for the plugin i created above, i have created a theme to add a Copy Page button with a drop down to ask about the contents directly to a LLM provider in their cloud chat. This is mimicking the behavior that we are beginning to see from big documentation providers like Mintlify.

    Example:

    Image Image

    The copyButton will render on any page that has a MD file generated for it.

    To accompany this, i also pushed a major upgrade for the plugin, which includes a overhaul of the config interface. For the most part its just a reorganization, but I also introduced Sections as a feature. Sections allow you to specify exactly what docs are housed under a section. You will also have the ability to add descriptions, title names, and subsections in a section object.

    I also added the ability t add attachedFiles which will parse the contents of the file and create a markdown file with its contents inside of it. Helpful for items that are useful for llms, but not handy as a doc (example would be a OpenAPI spec)

    Right now these additions are on the alpha tagged release, just in case feedback is provided and changes are needed. Once its in a comfortable state for a time period, i will do the official release.

    The alpha packages however can be found here:

    Plugin: https://www.npmjs.com/package/@signalwire/docusaurus-plugin-llms-txt/v/2.0.0-alpha.2

    Theme: https://www.npmjs.com/package/@signalwire/docusaurus-theme-llms-txt/v/1.0.0-alpha.3

  20. harupy commented on Nov 5, 2025

    @harupy

    @Devon-White Thanks for the plugin! It works like a charm: mlflow/mlflow#18676

  21. slorber commented on Feb 16, 2026

    @slorber
    Collaborator
  22. Tobbe commented on Feb 16, 2026

    @Tobbe

    I'm very happily using @Devon-White's plugin, but Lennat's blog post that @slorber links above has some additional tips and ideas that I'd like to try to implement. Thanks for sharing Sébastien!

  23. peterpeterparker commented on Apr 21, 2026

    @peterpeterparker

    To follow-up on my previous post in this thread and sharing in case it’s useful to anyone: I've tackled a remaining todo and enhanced my custom docusaurus.llms.plugin.ts.

    The plugin already generated llms.txt and Markdown files, it now also hooks into the HTML source file to append a <link> alternate reference pointing to the corresponding .md file.

    For example

    <link href="https://juno.build/docs/build/functions/development.md" rel="alternate" type="text/markdown">

    The idea came from a Reddit discussion and a blog post I stumbled upon, and I also noticed platforms like Vercel are also doing so in their documentation.

    Hope that helps.

  24. danielcalvolopez commented on Aug 28, 2026

    @danielcalvolopez

    Design proposal: official markdown output + llms.txt for Docusaurus

    This is an attempt at the design questions @slorber posed upthread (May 23, 2025), including the concrete one: "Given a specific sample site, what kind of LLMS file do you expect it to output, and why?" It's also meant to clear the bar set when closing #11420 — lay out the possible choices and their tradeoffs before writing any implementation. The only code behind this is a small feasibility spike whose numbers show up in section 4. Happy to share it, but the point of this post is the design.


    TL;DR

    • I think the core deliverable should be per-page markdown twins (/docs/foo → /docs/foo.md), with llms.txt as a thin index over them. The twins are useful to any agent that fetches URLs today, whether or not the llms.txt spec ends up winning.
    • Group and order llms.txt by sidebars. That's the human-curated information architecture every Docusaurus site already maintains, so v1 needs no new curation API. markdownBreadcrumb (your sketch) becomes the escape hatch rather than the default.
    • The hard problem is MDX → faithful markdown, and neither existing community architecture solves it: HTML-reconversion loses semantics, source-regex leaks or drops JSX. What I'm proposing instead: re-run the remark phase on doc sources using core's own preprocessors, keep ::: directives untransformed, and serialize the mdast through a component registry (known theme components get markdown equivalents, unknown ones unwrap to children and get counted in a build-time coverage report).
    • Plugin shape matches your postBuild sketch: a standalone @docusaurus/plugin-llms-txt, sitemap-style postBuild emission, docs metadata via allContent, route metadata (sourceFilePath) as the uniform fallback. No core changes needed for v1.
    • Response headers and Accept negotiation stay out of core, since that's past the SSG boundary. The plugin emits files; hosting recipes cover negotiation, including the Vary: Accept cache-poisoning trap.

    1. Reframing: markdown pages first, llms.txt second

    The skepticism in this thread ("not sure any crawler consumes it") is fair. llms.txt consumption by crawlers is genuinely unproven. But I'd argue the file is the least valuable part of this feature. What is consumed today, heavily, is plain markdown at predictable URLs: coding agents and chat assistants fetch docs pages mid-conversation, and what they currently get from a Docusaurus site is hydrated HTML — expensive in tokens, noisy, sometimes content-free without JS. Mintlify and Rspress ship markdown twins natively, Fumadocs documents it as a first-class recipe. Docusaurus is now the largest docs framework with nothing official.

    So I'd flip the usual framing:

    1. markdownPages — a .md twin per content route. Valuable on its own.
    2. llms.txt — an index of the twins (title + description per page). Nearly free once (1) exists.
    3. llms-full.txt — optional concatenation, opt-in, with a size warning.

    If llms.txt-the-spec dies, (1) still justifies the plugin. If it wins, Docusaurus is already compliant.

    2. What docusaurus.io's llms.txt should look like, and why

    Sections come from top-level sidebar categories, in sidebar order. Entries are [title](twin-url): description, using metadata docs already have (title, description/excerpt). The reason to lean on sidebars: they're the only human-curated hierarchy that exists on every Docusaurus site, so reusing them means zero new curation burden, and the output mirrors what maintainers already consider the right reading order. Deeper nesting flattens into a breadcrumb prefix on the link title — which is where a markdownBreadcrumb callback could slot in as an override later.

    This covers all four problems enumerated in the May 23 sketch — which routes are listed (every content-plugin route not excluded), how routes group under headings (sidebar categories), how headings are ordered, and how links are ordered within each group (sidebar order, both levels) — by reusing the structure that already encodes the maintainer's answer to each.

    Here's a trimmed version, with real titles and descriptions from website/docs:

    # Docusaurus
    
    > Docusaurus helps you ship beautiful documentation sites. Every page listed
    > here has a markdown twin at the same URL with `.md` appended — prefer those.
    
    ## Getting Started
    
    - [Introduction](https://docusaurus.io/docs.md): Docusaurus in 5 minutes
    - [Installation](https://docusaurus.io/docs/installation.md): How to install Docusaurus locally, and start a Docusaurus site in no time.
    - [Configuration](https://docusaurus.io/docs/configuration.md): Configuring your site's behavior and layout.
    
    ## Guides
    
    - [Creating Pages](https://docusaurus.io/docs/creating-pages.md): …
    - [Docs › Create a doc](https://docusaurus.io/docs/create-doc.md): …
    - [Markdown Features › Admonitions](https://docusaurus.io/docs/markdown-features/admonitions.md): Handling admonitions/callouts in Docusaurus Markdown.
      … (one line per doc, sidebar order)
    
    ## Advanced Guides
    ## Upgrading
    ## API Reference
    
    - [docusaurus.config.js](https://docusaurus.io/docs/api/docusaurus-config.md): API reference for Docusaurus configuration file.
      …
    
    ## Optional
    
    - [Blog](https://docusaurus.io/blog.md): release announcements and engineering posts
    - [Full documentation as one file](https://docusaurus.io/llms-full.txt)
    - [Sitemap](https://docusaurus.io/sitemap.xml)

    A few decisions baked into this, all of them debatable:

    • Links point at the .md twins, not the HTML pages. The file exists for agents; sending them to HTML defeats the purpose.
    • One ## per top-level sidebar category, one section per additional docs instance/sidebar, and blog under Optional (the llms.txt convention is that ## Optional marks skippable content).
    • Current version and default locale only, by default. Versioned/localized twins are an option rather than a default — llms.txt has no version concept and agents generally want the latest.
    • The header blockquote comes from siteConfig.tagline/description, overridable.

    3. Per-page markdown twins

    • URL scheme: permalink + .md (/docs/installation → /docs/installation.md; a permalink ending in / maps to …/index.md). These are static files emitted next to the HTML in outDir, so every host serves them with a sane content type without any configuration.
    • Content shape: # {title}, > {description}, serialized body, nothing else. No frontmatter by default (agents read prose; the metadata they need is in llms.txt), with an option to include it.
    • Discovery: llms.txt plus the predictable URL convention. A per-page <link rel="alternate" type="text/markdown"> would be nice, but a standalone plugin can't inject per-route head tags today, so I've flagged that as an open question rather than smuggling it into v1 scope. A "copy page as markdown" theme button is a natural follow-up once twins exist.

    4. The serialization core

    This is the part the existing ecosystem hasn't solved, and the reason "just copy the sources" and "just convert the HTML" both disappoint:

    • HTML → markdown reconversion (the signalwire architecture) is robust against unknown components but loses semantics: admonition types dissolve into styled divs, tab labels detach from tab content, code-block metadata disappears, and the output tracks theme markup rather than authored content.
    • Raw source processing (the rachfop architecture) leaks or regex-strips JSX, can't resolve imported partials, and doesn't handle Docusaurus-specific preprocessing (mdx-code-block fences, {#heading-ids}).

    The Sentry write-up shared earlier in this thread states the received wisdom: "we cannot go directly from MDX to Markdown, we had to render the HTML from MDX first and then convert it to Markdown, essentially doubling the work." I don't think that premise holds for Docusaurus. The mdast — after Docusaurus's own source preprocessors, before any rehype — still knows exactly what the author meant, and serializing from it is both direct and cheap.

    So the proposal is to serialize from the mdast:

    1. Preprocess sources with core's own exported utils (unwrapMdxCodeBlocks, admonitionTitleToDirectiveLabel from @docusaurus/utils). This is what makes patterns like <APITable> split across two mdx-code-block fences parse correctly.
    2. Parse with the remark phase only (remark-mdx + remark-directive + remark-gfm), without the admonition/mermaid/contentTitle transforms, so :::note is still a clean containerDirective.
    3. Clean the tree through a component serialization registry:
    Construct Serialization
    :::note / :::tip[Title], nested Blockquote with bold typed label (> **Warning: Title**), nesting preserved
    <Tabs> / <TabItem> Bold tab label + content per tab (**npm:** …)
    <details> / <Details> Bold summary + body
    <CodeBlock language title> Fenced code with language + title meta
    ```bash npm2yarn Left as the npm fence (no tab synthesis)
    <DocCardList /> Link list resolved from sidebar data
    <TOCInline /> Dropped (headings are already present)
    Imported partials (_*.mdx) Inlined (resolve the import, splice its mdast)
    Wrappers (APITable, BrowserWindow, …) Unwrapped to children
    Unknown components Unwrapped to children + counted in a build-time coverage report, overridable per component in config
    Imports/exports, {expressions}, heading {#ids} Dropped/stripped

    The registry is the extension point: theme authors and sites register serializers for their own components, the same way createSitemapItems customizes the sitemap.

    To sanity-check feasibility I ran the spike against six unmodified pages of website/docs — the Tabs, Admonitions, and Code-blocks guides, the docusaurus.config.js API reference, the CLI reference, and the MDX-and-React guide as a worst case. The serializer produced zero leftover JSX/imports/directives, preserved every heading (e.g. 40/40 on the config API reference) and every table (including the APITable-wrapped ones), retained ≥99% of visible text, and ran at 11–66ms per page. Unknown-component degradation behaved as designed on the React stress page: a custom <Highlight> unwrapped to its children, and a partial import surfaced in the coverage report instead of silently vanishing.

    To be upfront about what degrades: components whose content only exists at runtime (live demos, BrowserOnly, code blocks built from JS expressions) fall back to their children or a recorded drop. The coverage report makes every such loss visible at build time instead of silent.

    Before/after excerpts from the spike (unmodified pages of website/docs)

    From markdown-features-tabs.mdx — an mdx-code-block live demo wrapping a theme component wrapping tabs:

    ```mdx-code-block
    <BrowserWindow>
      <Tabs>
        <TabItem value="apple" label="Apple">This is an apple 🍎</TabItem>
        <TabItem value="orange" label="Orange">This is an orange 🍊</TabItem>
        <TabItem value="banana" label="Banana">This is a banana 🍌</TabItem>
      </Tabs>
    </BrowserWindow>
    ```

    serializes to:

    **Apple:** This is an apple 🍎
    
    **Orange:** This is an orange 🍊
    
    **Banana:** This is a banana 🍌

    From markdown-features-admonitions.mdx — nested admonitions with legacy titles:

    :::::info Parent
    
    Parent content
    
    ::::danger Child
    
    Child content
    
    :::tip Deep Child
    
    Deep child content
    
    :::
    
    ::::
    
    :::::

    serializes to:

    > **Info: Parent**
    >
    > Parent content
    >
    > > **Danger: Child**
    > >
    > > Child content
    > >
    > > > **Tip: Deep Child**
    > > >
    > > > Deep child content

    (The code-fence examples of these syntaxes on the same pages stay verbatim — the serializer only transforms live constructs.)

    5. Plugin architecture

    This matches the postBuild sketch from May 2025, and nothing here requires core changes:

    • A standalone plugin (@docusaurus/plugin-llms-txt) rather than a docs-plugin feature, because it has to see docs (multi-instance), blog, and pages uniformly.
    • allContentLoaded: read docs/blog metadata and sidebars (for grouping and ordering) from allContent.
    • postBuild: serialize each route's source (route metadata sourceFilePath is the plugin-agnostic mapping), write twins + llms.txt into outDir. This is exactly the sitemap plugin's emission pattern, including its hash-router guard. Source files are read at postBuild, not loadContent, which matches the preference stated upthread: prod-only generation, no dev/hot-reload cost.
    • The serializer ships as an exported util so the community can reuse it (copy-page buttons, search indexing) without the plugin.
    • Build cost is remark-parse only — no compile, no SSG — so it's negligible next to MDX compilation, and parallelizable.

    Config sketch, kept small on purpose (every option should have to earn its place):

    [
      '@docusaurus/plugin-llms-txt',
      {
        markdownPages: true,
        llmsTxt: true,
        llmsFullTxt: false,
        ignoreRoutes: ['/changelog/**'],
        serializeComponent: {
          // site-specific components; same spirit as createSitemapItems
          MyChart: (node, {children}) => children,
        },
      },
    ]

    6. What stays out of core

    Docusaurus is a static-site generator: it has no header or negotiation mechanism, and this design doesn't add one. Accept: text/markdown negotiation is a hosting concern, and a sharp-edged one — rewriting negotiated responses without Vary: Accept cache-poisons CDNs into serving markdown to browsers (or HTML to agents). The plugin's job ends at emitting correct static files. A documentation recipe per host (Vercel/Netlify/Cloudflare) can show optional negotiation configs with the Vary warning attached. Static .md twins deliberately don't need any of it.

    7. Testing and rollout

    • Testing: golden-fixture round-trips over website/docs pages with mechanical gates — zero MDX residue in output, heading/table/code-block counts preserved, visible-text retention ratio. All deterministic, no LLM in the loop.
    • Rollout: (1) plugin in the monorepo, dogfooded on docusaurus.io — which would also resolve the currently-stalled website-local attempt (feat(website): add agent docs plugin #11958) with the official mechanism; (2) hosting recipes; (3) preset-classic integration once stable, candidate for default-on in a 4.x minor. That matches the direction stated in Docusaurus V4 - Umbrella issue #11719: an official solution "in 4.x but not 4.0."

    8. Open questions for maintainers

    1. Admonition output: labelled blockquote (portable everywhere) or ::: passthrough (round-trips into Docusaurus, unrenderable elsewhere)?
    2. Should twins exist for versioned/localized routes? The URL scheme is ready for it; I'd propose default off.
    3. Twins: pure markdown vs. optional YAML frontmatter (source_url, last_updated)?
    4. Where does the default component registry live — the plugin (knows serialization) or theme-classic (owns component semantics)?
    5. Per-page <link rel="alternate" type="text/markdown">: worth a small core/theme hook, or defer?
    6. Blog in llms.txt by default, or docs-only?

    9. Prior art

    • @signalwire/docusaurus-plugin-llms-txt — postBuild HTML→markdown reconversion; most-installed; v2 in alpha since Nov 2025. Robust to unknown components, loses authored semantics.
    • docusaurus-plugin-llms (rachfop) — MDX source processing with heuristic cleaning; actively maintained; open fidelity issues around JSX content, partials, paths.
    • docusaurus-plugin-llms-txt (din0s) — single 2024 release.
    • PR feat: add @docusaurus/plugin-llms-txt #11420 — closed for being implementation-without-design; this document aims to be the missing design.
    • Native support elsewhere: Mintlify (default), Rspress (one flag), Fumadocs (core utilities + recipes).

    Happy to iterate on any section, generate the full llms.txt for docusaurus.io from a local build as a concrete artifact, or turn the serialization core into a PR once the team agrees on a direction. The spike (serializer + fixture checks) is small and I can share it as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions