Skip to content

Automatically generates /llms.txt markdown documentation for your Nuxt application.

License

Notifications You must be signed in to change notification settings

nuxtlabs/nuxt-llms

Repository files navigation

nuxt-llms-social-card

Nuxt LLMs

npm version npm downloads License Nuxt

Nuxt LLMs automatically generates llms.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.

Features

  • 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

Quick Setup

  1. Install the module:
npm i nuxt-llms
  1. Register nuxt-llms in your nuxt.config.ts:
export default defineNuxtConfig({
  modules: ['nuxt-llms']
})
  1. Configure your application details:
export default defineNuxtConfig({
  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 ✨

Options

  • domain(required): The domain of the application
  • title: The title of the application, will be displayed at the top of the documentation
  • description: The description of the application, will be displayed at the top of the documentation right after the title
  • sections: 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 section
    • description: The description of the section
    • links: The links of the section
      • title(required): The title of the link
      • description: The description of the link
      • href(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: The llms_full.txt configuration. Setting this option will enable the llms_full.txt route.
    • title: The title of the llms_full documentation
    • description: The description of the llms_full documentation

Documentation Formats

The module generates two different documentation formats:

llms.txt

The /llms.txt route generates a concise, structured documentation that follows the llms.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

llms_full.txt

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 the llms_full.txt route, you need to enable it by setting full.title and full.description in your nuxt.config.ts.

export default defineNuxtConfig({
  llms: {
    domain: 'https://example.com',
    title: 'My Application',
    full: {
      title: 'Full Documentation',
      description: 'Full documentation of the application',
    },
  },
})

Extending the documentation using hooks

The module provides a hooks system that allows you to dynamically extend both documentation formats. There are two main hooks:

Available Hooks

llms:generate(event, options)

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 event
  • options: ModuleOptions - The module options that you can modify to add sections, links, etc.

llms:generate:llms_full(event, options, contents)

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 event
  • options: 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

Using Hooks in Your Application

Create a server plugin in your server/plugins directory:

// server/plugins/llms.ts
export default defineNitroPlugin((nitroApp) => {
  // Method 1: Using the hooks directly
  nitroApp.hooks.hook('llms:generate', (event, options) => {
    // Add a new section to llms.txt
    options.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 function
  nitroApp.hooks.hook('llms:generate:full', (event, options, contents) => {
    // Add detailed documentation to llms_full.txt
    contents.push(`## API Authentication

### Bearer Token
To authenticate API requests, include a Bearer token in the Authorization header:

\`\`\`
Authorization: Bearer <your-token>
\`\`\`

### API Keys
For server-to-server communication, use API keys:

\`\`\`
X-API-Key: <your-api-key>
\`\`\`
    `)
  })
})

Using Hooks in Nuxt Modules

If you're developing a Nuxt module that needs to extend the LLMs documentation:

  1. Create a server plugin in your module:
// module/runtime/server/plugins/my-module-llms.ts
export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('llms:generate', (event, options) => {
    options.sections.push({
      title: 'My Module',
      description: 'Documentation for my module features',
      links: [/* ... */]
    })
  })
})
  1. Register the plugin in your module setup:
import { defineNuxtModule, addServerPlugin } from '@nuxt/kit'
import { fileURLToPath } from 'url'

export default defineNuxtModule({
  setup(options, nuxt) {
    const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
    addServerPlugin(resolve(runtimeDir, 'server/plugins/my-module-llms'))
  }
})

Integrations

Nuxt Content

Nuxt Content ^3.2.0 comes with built-in support for LLMs documentation. You can use nuxt-llms with @nuxt/content to efficiently write content and documentation for your website and generate LLM-friendly documentation without extra effort. Content module uses nuxt-llms hooks and automatically adds all your contents into llms.txt and llms_full.txt documentation.

All you need is to install both modules and write your content files in the content directory.

export default defineNuxtConfig({
  modules: ['nuxt-llms', '@nuxt/content'],
  llms: {
    domain: 'https://example.com',
    title: 'My Application',
    description: 'My Application Description',
  },
})

Checkout the Nuxt Content documentation for more information on how to write your content files.

And checkout the Nuxt Contnet llms documentation for more information on how to customize LLMs contents with nuxt-llms and @nuxt/content.

💻 Development

  • 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

License

MIT License

Copyright (c) NuxtLabs