UNPKG

vitepress-plugin-llms

Version:

šŸ“œ A VitePress plugin for generating LLM-friendly documentation

261 lines (178 loc) • 12.8 kB
<!-- markdownlint-capture --> <!-- markdownlint-disable no-inline-html heading-start-left first-line-h1 --> <div align="center"> <b>Is this plugin useful for your site? Consider <a href="https://github.com/sponsors/okineadev">sponsoring the developer</a> to support the project's development 😺</b> <br><br> <a href="https://npmx.com/package/vitepress-plugin-llms"> <!-- https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to --> <picture> <source media="(prefers-color-scheme: dark)" srcset="assets/hero-dark.png"> <source media="(prefers-color-scheme: light)" srcset="assets/hero-light.png"> <img src="assets/hero-dark.png" alt="Banner"> </picture> </a> <!-- prettier-ignore-start --> # šŸ“œ vitepress-plugin-llms [![NPM Downloads](https://img.shields.io/npm/dw/vitepress-plugin-llms?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAtOTYwIDk2MCA5NjAiIHdpZHRoPSIyNHB4IiBmaWxsPSIjMDAwMDAwIj48cGF0aCBkPSJNNDgwLTMyMCAyODAtNTIwbDU2LTU4IDEwNCAxMDR2LTMyNmg4MHYzMjZsMTA0LTEwNCA1NiA1OC0yMDAgMjAwWk0xNjAtMTYwdi0yMDBoODB2MTIwaDQ4MHYtMTIwaDgwdjIwMEgxNjBaIi8%2BPC9zdmc%2B&labelColor=FAFAFA&color=212121)](https://npmx.dev/package/vitepress-plugin-llms) [![NPM Version](https://img.shields.io/npm/v/vitepress-plugin-llms?label=.%2Fnpmx&labelColor=FAFAFA&color=212121)](https://npmx.dev/package/vitepress-plugin-llms) [![Tests Status](https://img.shields.io/github/actions/workflow/status/okineadev/vitepress-plugin-llms/ci.yml?label=tests&labelColor=212121)](https://github.com/okineadev/vitepress-plugin-llms/actions/workflows/ci.yml) [![Built with Bun](https://img.shields.io/badge/Built_with-Bun-fbf0df?logo=bun&labelColor=212121)](https://bun.sh) [![Formatted with oxfmt](https://github.com/user-attachments/assets/bbae5797-1160-4256-a838-0b51bff4370e)](https://oxc.rs/) [![sponsor](https://img.shields.io/badge/sponsor-EA4AAA?logo=githubsponsors&labelColor=FAFAFA)](https://github.com/sponsors/okineadev) [šŸ› Report bug](https://github.com/okineadev/vitepress-plugin-llms/issues/new?template=bug-report.yml) • [Request feature ✨](https://github.com/okineadev/vitepress-plugin-llms/issues/new?template=feature-request.yml) </div> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> ## šŸ“¦ Installation ```bash npm install vitepress-plugin-llms --save-dev ``` ## šŸ› ļø Usage Add the Vite plugin to your VitePress configuration (`.vitepress/config.ts`): ```ts import { defineConfig } from 'vitepress' import llmstxt from 'vitepress-plugin-llms' export default defineConfig({ vite: { plugins: [llmstxt()], }, }) ``` Now, thanks to this plugin, the LLM version of the website documentation is automatically generated > [!NOTE] > > **For repositories with documentation in other languages:** Please do not use this plugin, only English documentation is enough for LLMs. --- <!-- markdownlint-capture --> <!-- markdownlint-disable no-inline-html --> > [!TIP] > You can add <kbd>šŸ“‹ Copy as Markdown</kbd> and <kbd>šŸ“„ Download as Markdown</kbd> buttons for each page so that visitors can copy the page in Markdown format with just one click! > > <img src="./assets/copy-as-markdown-buttons-screenshot.png" width="400" alt="Screenshot"> <!-- markdownlint-restore --> First, register a global component with buttons in `docs/.vitepress/theme/index.ts`: ```ts import DefaultTheme from 'vitepress/theme' import type { Theme } from 'vitepress' import CopyOrDownloadAsMarkdownButtons from 'vitepress-plugin-llms/vitepress-components/CopyOrDownloadAsMarkdownButtons.vue' export default { extends: DefaultTheme, enhanceApp({ app }) { app.component('CopyOrDownloadAsMarkdownButtons', CopyOrDownloadAsMarkdownButtons) }, } satisfies Theme ``` And tell VitePress to use an additional Markdown plugin that will insert them: ```ts import { defineConfig } from 'vitepress' import { copyOrDownloadAsMarkdownButtons } from 'vitepress-plugin-llms' export default defineConfig({ // ... markdown: { config(md) { md.use(copyOrDownloadAsMarkdownButtons) }, }, }) ``` If you want to build your **own UI** instead of using the bundled Vue component, you can consume the shared composable directly: ```ts import { useCopyOrDownloadAsMarkdownButtons } from 'vitepress-plugin-llms/vitepress-components' ``` --- ### āœ… Good practices #### 1. Use `description` in the pages frontmatter Typically, the list of pages in llms.txt is generated like this: ```markdown - [Tailwind v4](/docs/tailwind-v4.md) ``` As you can see, it's not very clear what's on this page and what it's for But you can insert `description` in frontmatter in the `docs/tailwind-v4.md` file: ```markdown --- description: How to use shadcn-vue with Tailwind v4. --- ... ``` And the link in the generated `llms.txt` will display the page description: ```markdown - [Tailwind v4](/docs/tailwind-v4.md): How to use shadcn-vue with Tailwind v4. ``` ### Plugin Configuration <!-- markdownlint-capture --> <!-- markdownlint-disable no-inline-html --> > [!NOTE] > In most cases you **don't need** any additional configuration because **everything works out of the box**, but if you do need to customize it, please see your IDE hints or see <a href="src/types.d.ts">`src/types.d.ts`</a> or <a href="https://deepwiki.com/okineadev/vitepress-plugin-llms"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki" align="center"/></a> <!-- markdownlint-restore --> ### Extended markup for content management #### Embedding content specifically for LLMs with `<llm-only>` tag You can add a content that will be visible in files for LLMs, but invisible to humans, this can be useful for setting special instructions like "Refer to #basic-queries for demonstrations", "NEVER do ....", "ALWAYS use ... in case of ..." etc. To do this, you need to wrap content with the `<llm-only>` tag: ```markdown <llm-only> ## Section for LLMs This content appears only in the generated LLMs files without the `<llm-only>` tag </llm-only> ``` Or ```markdown Check out the Plugins API Guide for documentation about creating plugins. <llm-only>Note for LLM...</llm-only> ``` #### Excluding content for LLMs with the `<llm-exclude>` tag You can add a content that will be visible in files for humans, but invisible to LLMs, opposite of `<llm-only>`: ```markdown <llm-exclude> ## Section for humans This content will not be in the generated files for LLMs </llm-exclude> ``` Or ```markdown Check out the Plugins API Guide for documentation about creating plugins. <llm-exclude>Note only for humans</llm-exclude> ``` ## šŸš€ Why `vitepress-plugin-llms`? LLMs (Large Language Models) are great at processing text, but traditional documentation formats can be too heavy and cluttered. `vitepress-plugin-llms` generates raw Markdown documentation that LLMs can efficiently process The file structure in `.vitepress/dist` folder will be as follows: ```plaintext šŸ“‚ .vitepress/dist ā”œā”€ā”€ ... ā”œā”€ā”€ llms-full.txt // A file where all the website documentation is compiled into one file ā”œā”€ā”€ llms.txt // The main file for LLMs with all links to all sections of the documentation for LLMs ā”œā”€ā”€ markdown-examples.html // A human-friendly version of `markdown-examples` section in HTML format └── markdown-examples.md // A LLM-friendly version of `markdown-examples` section in Markdown format ``` ### āœ… Key Features - āš”ļø Easy integration with VitePress - āœ… Zero config required, everything works out of the box - āš™ļø Customizable - šŸ¤– An LLM-friendly version is generated for each page - šŸ“ Generates `llms.txt` with section links - šŸ“– Generates `llms-full.txt` with all content in one file ## šŸ“– [llmstxt.org](https://llmstxt.org/) Standard This plugin follows the [llmstxt.org](https://llmstxt.org/) standard, which defines the best practices for LLM-friendly documentation. ## āœ… The most popular projects that trust this plugin This plugin is used by the most popular projects including [**Vite**](https://vite.dev), [**Vue.js**](https://vuejs.org), [**Vitest**](https://vitest.dev), [**Rolldown**](https://rolldown.rs) and many other incredible projects that won't fit on this list <!-- prettier-ignore-start --> <!-- markdownlint-disable-next-line no-inline-html --> [<img alt="Dependents" src="https://dependents.info/okineadev/vitepress-plugin-llms/image" height="50">](https://dependents.info/okineadev/vitepress-plugin-llms) <!-- prettier-ignore-end --> ### Early adopters Here is a list of less popular but no less cool projects that were the first to pick up this plugin, thereby helping others discover this plugin | Project | Stars | `llms.txt` | `llms-full.txt` | | -------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------: | :-------------------------------------------------------------: | | [**shadcn/vue**](https://shadcn-vue.com/) | [![Stars](https://img.shields.io/github/stars/unovue/shadcn-vue?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/unovue/shadcn-vue) | [llms.txt](https://shadcn-vue.com/llms.txt) | [llms-full.txt](https://shadcn-vue.com/llms-full.txt) | | [**Fantastic-admin**](https://fantastic-admin.hurui.me/) | [![Stars](https://img.shields.io/github/stars/fantastic-admin/basic?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/fantastic-admin/basic) | [llms.txt](https://fantastic-admin.hurui.me/llms.txt) | [llms-full.txt](https://fantastic-admin.hurui.me/llms-full.txt) | | [**Vue Macros**](https://vue-macros.dev/) | [![Stars](https://img.shields.io/github/stars/vue-macros/vue-macros?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/vue-macros/vue-macros) | [llms.txt](https://vue-macros.dev/llms.txt) | [llms-full.txt](https://vue-macros.dev/llms-full.txt) | | [**oRPC**](https://orpc.unnoq.com/) | [![Stars](https://img.shields.io/github/stars/middleapi/orpc?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/middleapi/orpc) | [llms.txt](https://orpc.unnoq.com/llms.txt) | [llms-full.txt](https://orpc.unnoq.com/llms-full.txt) | | [**tsdown**](https://tsdown.dev/) | [![Stars](https://img.shields.io/github/stars/rolldown/tsdown?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/rolldown/tsdown) | [llms.txt](https://tsdown.dev/llms.txt) | [llms-full.txt](https://tsdown.dev/llms-full.txt) | | [**GramIO**](https://gramio.dev/) | [![Stars](https://img.shields.io/github/stars/gramiojs/gramio?style=flat&label=%E2%AD%90&labelColor=FAFAFA&color=212121)](https://github.com/gramiojs/gramio) | [llms.txt](https://gramio.dev/llms.txt) | [llms-full.txt](https://gramio.dev/llms-full.txt) | Also big thanks to [@yyx990803](https://github.com/yyx990803) who agreed to integrate this plugin into all projects of the [**VoidZero**](https://voidzero.dev) ecosystem, [**Vue.js**](https://vuejs.org) and shared about this plugin with the world on X, thanks to which this plugin has gained such popularity šŸ’ ## ā¤ļø Support If you like this project, consider supporting it by starring ⭐ it on GitHub, sharing it with your friends, or [buying me a coffee ā˜•](https://github.com/sponsors/okineadev) ## šŸ¤ Contributing You can read the instructions for contributing here - [CONTRIBUTING.md](./CONTRIBUTING.md) ## šŸ“œ License <!-- spell-checker:disable-next-line --> [MIT License](./LICENSE) Ā© 2025-present [Yurii Bogdan](https://github.com/okineadev) ## šŸ‘Øā€šŸ­ Contributors Thank you to everyone who helped with the project! ![Contributors](https://contributors-table.vercel.app/image?repo=okineadev/vitepress-plugin-llms&width=50&columns=15) [![Sponsors](https://raw.githubusercontent.com/okineadev/static/main/sponsors.svg)](https://github.com/sponsors/okineadev)