- Notifications
You must be signed in to change notification settings - Fork1
Automatically generates /llms.txt markdown documentation for your Nuxt application.
License
nuxtlabs/nuxt-llms
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Nuxt LLMs automatically generatesllms.txt
markdown documentation for your Nuxt application. It provides runtime hooks to collect data from various sources (CMS, Nuxt Content, etc.) and generate structured documentation in a text-based format.
- Generates & prerenders
/llms.txt
automatically - Generate & prerenders
/llms_full.txt
when enabled - Customizable sections directly from your
nuxt.config.ts
- Integrates with Nuxt modules and your application via the runtime hooks system
- Install the module:
npm i nuxt-llms
- Register
nuxt-llms
in yournuxt.config.ts
:
exportdefaultdefineNuxtConfig({modules:['nuxt-llms']})
- Configure your application details:
exportdefaultdefineNuxtConfig({modules:['nuxt-llms'],llms:{domain:'https://example.com',title:'My Application',description:'My Application Description',sections:[{title:'Section 1',description:'Section 1 Description',links:[{title:'Link 1',description:'Link 1 Description',href:'/link-1',},{title:'Link 2',description:'Link 2 Description',href:'/link-2',},],},],},})
That's it! You can visit/llms.txt
to see the generated documentation ✨
domain
(required): The domain of the applicationtitle
: The title of the application, will be displayed at the top of the documentationdescription
: The description of the application, will be displayed at the top of the documentation right after the titlesections
: The sections of the documentation.Section are consisted of a title, one or more paragraphs of description and possibly a list of links.Each section is an object with the following properties:title
(required): The title of the sectiondescription
: The description of the sectionlinks
: The links of the sectiontitle
(required): The title of the linkdescription
: The description of the linkhref
(required): The href of the link
notes
: The notes of the documentation. Notes are a special section which always appears at the end of the documentation. Notes are useful to add any information about the application or documentation itself.full
: Thellms_full.txt
configuration. Setting this option will enable thellms_full.txt
route.title
: The title of the llms_full documentationdescription
: The description of the llms_full documentation
The module generates two different documentation formats:
The/llms.txt
route generates a concise, structured documentation that follows thellms.txt specification. This format is optimized for both human readability and AI consumption. It includes:
- Application title and description
- Organized sections with titles and descriptions
- Links with titles, descriptions, and URLs
- Optional notes section
The/llms_full.txt
route provides a more detailed, free-form documentation format. This is useful to reduce crawler traffic on your application and provide a more detailed documentation to your users and LLMs.
By default module does not generate thellms_full.txt
route, you need to enable it by settingfull.title
andfull.description
in yournuxt.config.ts
.
exportdefaultdefineNuxtConfig({llms:{domain:'https://example.com',title:'My Application',full:{title:'Full Documentation',description:'Full documentation of the application',},},})
The module provides a hooks system that allows you to dynamically extend both documentation formats. There are two main hooks:
This hook is called for every request to/llms.txt
. Use this hook to modify the structured documentation, It allows you to add sections, links, and metadata.
Parameters:
event
: H3Event - The current request eventoptions
: ModuleOptions - The module options that you can modify to add sections, links, etc.
This hook is called for every request to/llms_full.txt
. It allows you to add custom content sections in any format.
Parameters:
event
: H3Event - The current request eventoptions
: ModuleOptions - The module options that you can modify to add sections, links, etc.contents
: string[] - Array of content sections you can add to or modify
Create a server plugin in yourserver/plugins
directory:
// server/plugins/llms.tsexportdefaultdefineNitroPlugin((nitroApp)=>{// Method 1: Using the hooks directlynitroApp.hooks.hook('llms:generate',(event,options)=>{// Add a new section to llms.txtoptions.sections.push({title:'API Documentation',description:'REST API endpoints and usage',links:[{title:'Authentication',description:'API authentication methods',href:`${options.domain}/api/auth`}]})})// Method 2: Using the helper functionnitroApp.hooks.hook('llms:generate:full',(event,options,contents)=>{// Add detailed documentation to llms_full.txtcontents.push(`## API Authentication### Bearer TokenTo authenticate API requests, include a Bearer token in the Authorization header:\`\`\`Authorization: Bearer <your-token>\`\`\`### API KeysFor server-to-server communication, use API keys:\`\`\`X-API-Key: <your-api-key>\`\`\` `)})})
If you're developing a Nuxt module that needs to extend the LLMs documentation:
- Create a server plugin in your module:
// module/runtime/server/plugins/my-module-llms.tsexportdefaultdefineNitroPlugin((nitroApp)=>{nitroApp.hooks.hook('llms:generate',(event,options)=>{options.sections.push({title:'My Module',description:'Documentation for my module features',links:[/* ... */]})})})
- Register the plugin in your module setup:
import{defineNuxtModule,addServerPlugin}from'@nuxt/kit'import{fileURLToPath}from'url'exportdefaultdefineNuxtModule({setup(options,nuxt){construntimeDir=fileURLToPath(newURL('./runtime',import.meta.url))addServerPlugin(resolve(runtimeDir,'server/plugins/my-module-llms'))}})
Nuxt Content ^3.2.0 comes with built-in support for LLMs documentation. You can usenuxt-llms
with@nuxt/content
to efficiently write content and documentation for your website and generate LLM-friendly documentation without extra effort. Content module usesnuxt-llms
hooks and automatically adds all your contents intollms.txt
andllms_full.txt
documentation.
All you need is to install both modules and write your content files in thecontent
directory.
exportdefaultdefineNuxtConfig({modules:['nuxt-llms','@nuxt/content'],llms:{domain:'https://example.com',title:'My Application',description:'My Application Description',},})
Checkout theNuxt Content documentation for more information on how to write your content files.
And checkout theNuxt Content llms documentation for more information on how to customize LLMs contents withnuxt-llms
and@nuxt/content
.
- Clone repository
- Install dependencies using
pnpm install
- Prepare using
pnpm dev:prepare
- Build using
pnpm prepack
- Try playground using
pnpm dev
- Test using
pnpm test
Copyright (c) NuxtLabs
About
Automatically generates /llms.txt markdown documentation for your Nuxt application.