Skip to content

Commit a657793

Browse files
committed
docs: add llms raw markdown config
1 parent 2b32a4d commit a657793

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

docs/content/docs/2.collections/2.types.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ Nuxt Content will automatically generate a path for each file in the collection,
3333

3434
Here are examples of generated paths based on file structure:
3535

36-
| | |
37-
| -------------------------------- | --------------------- |
38-
| | |
3936
| File | Path |
37+
| -------------------------------- | --------------------- |
4038
| `content/index.md` | `/` |
4139
| `content/about.md` | `/about` |
4240
| `content/blog/index.md` | `/blog` |

docs/content/docs/7.integrations/02.llms.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ export default defineNuxtConfig({
3131

3232
That's it 🚀 `/llms.txt` file is automatically generated and pre-rendered.
3333

34+
## Raw markdown access
35+
36+
When `nuxt-llms` is enabled, Nuxt Content also exposes a raw markdown endpoint so you can stream LLM-ready source files without going through the full rendering pipeline.
37+
38+
- **Endpoint**: `/raw/<content-path>.md` (use the same path as the page URL, drop trailing `/index`, and keep the `.md` extension), returning `text/markdown; charset=utf-8`.
39+
- **Scope**: only `page` collections are included; exclude specific collections with `llms.contentRawMarkdown.excludeCollections`{lang=ts}. Set `llms.contentRawMarkdown = false`{lang=ts} to disable the endpoint entirely.
40+
- **Output**: if the requested document is missing a top-level heading or description, the route prepends the title and description to the markdown body before returning it.
41+
- **llms.txt links**: document links generated in `llms.txt` are automatically rewritten to the `/raw/...md` endpoint (unless the collection is excluded or the feature is disabled) so agents fetch compact markdown instead of full HTML, reducing token usage and improving response speed.
42+
43+
```ts [nuxt.config.ts]
44+
export default defineNuxtConfig({
45+
modules: ['@nuxt/content', 'nuxt-llms'],
46+
llms: {
47+
contentRawMarkdown: {
48+
// Optional: prevent specific page collections from being exposed
49+
excludeCollections: ['blog'],
50+
},
51+
},
52+
})
53+
```
54+
3455
## Sections
3556

3657
When generating content, you can create custom sections to process your content into LLM-friendly formats.

docs/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default defineNuxtConfig({
5353
title: 'Complete Documentation',
5454
description: 'The complete documentation including all content',
5555
},
56-
contentRawMD: {
56+
contentRawMarkdown: {
5757
excludeCollections: ['landing'],
5858
},
5959
},

src/features/llms/module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export default defineNuxtModule({
1010
const { resolve } = createResolver(import.meta.url)
1111

1212
addServerPlugin(resolve('runtime/server/content-llms.plugin'))
13-
if ((nuxt.options as unknown as { llms: { contentRawMD: false | { excludeCollections: string[] } } })?.llms?.contentRawMD !== false) {
13+
if ((nuxt.options as unknown as { llms: { contentRawMarkdown: false | { excludeCollections: string[] } } })?.llms?.contentRawMarkdown !== false) {
1414
addServerHandler({ route: '/raw/**:slug.md', handler: resolve('runtime/server/routes/raw/[...slug].md.get') })
1515
}
1616

1717
nuxt.hook('modules:done', () => {
1818
// @ts-expect-error -- TODO: fix types
1919
nuxt.options.llms ||= {}
2020
// @ts-expect-error -- TODO: fix types
21-
nuxt.options.llms.contentRawMD = defu(nuxt.options.llms.contentRawMD, {
21+
nuxt.options.llms.contentRawMarkdown = defu(nuxt.options.llms.contentRawMarkdown, {
2222
excludeCollections: [],
2323
})
2424

2525
nuxt.options.runtimeConfig.llms ||= {}
2626
// @ts-expect-error -- TODO: fix types
27-
nuxt.options.runtimeConfig.llms.contentRawMD = defu(nuxt.options.llms.contentRawMD, {
27+
nuxt.options.runtimeConfig.llms.contentRawMarkdown = defu(nuxt.options.llms.contentRawMarkdown, {
2828
excludeCollections: [],
2929
})
3030
})
@@ -36,7 +36,7 @@ export default defineNuxtModule({
3636
import type { SQLOperator, PageCollections, PageCollectionItemBase } from '@nuxt/content'
3737
declare module 'nuxt-llms' {
3838
interface ModuleOptions {
39-
contentRawMD?: false | {
39+
contentRawMarkdown?: false | {
4040
excludeCollections?: string[]
4141
}
4242
}

src/features/llms/runtime/server/content-llms.plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export default defineNitroPlugin((nitroApp: NitroApp) => {
9191
}
9292

9393
function getDocumentLink(link: string, collection: string, options: ModuleOptions) {
94-
const contentRawMD = (options as unknown as { contentRawMD: false | { excludeCollections: string[] } })?.contentRawMD
95-
if (contentRawMD === false || contentRawMD?.excludeCollections?.includes(collection)) {
94+
const contentRawMarkdown = (options as unknown as { contentRawMarkdown: false | { excludeCollections: string[] } })?.contentRawMarkdown
95+
if (contentRawMarkdown === false || contentRawMarkdown?.excludeCollections?.includes(collection)) {
9696
return withBase(link, options.domain)
9797
}
9898

src/features/llms/runtime/server/routes/raw/[...slug].md.get.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import collections from '#content/manifest'
88

99
export default eventHandler(async (event) => {
1010
const config = useRuntimeConfig(event)
11-
const llmsConfig = config.llms as { contentRawMD: false | { excludeCollections: string[] } }
11+
const llmsConfig = config.llms as { contentRawMarkdown: false | { excludeCollections: string[] } }
1212
const slug = getRouterParams(event)['slug.md']
13-
if (!slug?.endsWith('.md') || llmsConfig?.contentRawMD === false) {
13+
if (!slug?.endsWith('.md') || llmsConfig?.contentRawMarkdown === false) {
1414
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
1515
}
1616

@@ -19,7 +19,7 @@ export default eventHandler(async (event) => {
1919
path = path.substring(0, path.length - 6)
2020
}
2121

22-
const excludeCollections = llmsConfig?.contentRawMD?.excludeCollections || []
22+
const excludeCollections = llmsConfig?.contentRawMarkdown?.excludeCollections || []
2323
const _collections = Object.entries(collections as Record<string, ResolvedCollection>)
2424
.filter(([_key, value]) => value.type === 'page' && !excludeCollections.includes(_key))
2525
.map(([key]) => key) as string[]

0 commit comments

Comments
 (0)