Skip to content

Commit fadaf71

Browse files
authored
feat(llms): add related links to raw markdown endpoint (#3724)
1 parent 68f3c4b commit fadaf71

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

playground/content.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const content = defineCollection({
3636
date: z.date(),
3737
rawbody: z.string(),
3838
testd: property(z.object({})).inherit('components/TestD.vue'),
39+
links: z.array(z.object({
40+
label: z.string(),
41+
icon: z.string(),
42+
to: z.string(),
43+
})),
3944
}),
4045
})
4146

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Links Test
3+
description: A page to test frontmatter links in raw markdown output.
4+
links:
5+
- label: Source
6+
icon: i-simple-icons-github
7+
to: https://github.com/nuxt/content
8+
size: sm
9+
- label: Documentation
10+
icon: i-lucide-book-open
11+
to: https://content.nuxt.com
12+
size: sm
13+
---
14+
15+
## Introduction
16+
17+
This page tests that frontmatter metadata (including `links`) is correctly included in the raw markdown output.
18+
19+
Visit `/raw/real-content/links-test.md` to see the raw output with frontmatter.
20+
21+
## Content
22+
23+
Some example content to verify the body is still rendered correctly alongside the frontmatter.

playground/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export default defineNuxtConfig({
33
'@nuxt/ui',
44
'@nuxthub/core',
55
'@nuxt/content',
6+
'nuxt-llms',
67
],
78
content: {
89
experimental: {
@@ -42,4 +43,8 @@ export default defineNuxtConfig({
4243
// Or use PGlite with NuxtHub:
4344
// db: 'postgresql',
4445
},
46+
llms: {
47+
domain: 'http://localhost:3000',
48+
title: 'Content Playground',
49+
},
4550
})

playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"better-sqlite3": "^12.6.0",
1818
"drizzle-orm": "^0.45.1",
1919
"nuxt": "^4.2.2",
20+
"nuxt-llms": "^0.2.0",
2021
"pg": "^8.17.1",
2122
"remark-code-import": "^1.2.0",
2223
"shiki-transformer-color-highlight": "^1.0.0"

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { withLeadingSlash } from 'ufo'
22
import { stringify } from 'minimark/stringify'
33
import { queryCollection } from '@nuxt/content/server'
44
import type { Collections, PageCollectionItemBase, ResolvedCollection } from '@nuxt/content'
5+
import type { MinimarkNode } from '../../../../../../types/tree'
56
import { getRouterParams, eventHandler, createError, setHeader } from 'h3'
67
import { useRuntimeConfig } from '#imports'
78
import collections from '#content/manifest'
@@ -42,6 +43,18 @@ export default eventHandler(async (event) => {
4243
page.body.value.unshift(['h1', {}, page.title])
4344
}
4445

46+
// Append related links at the end if present
47+
const links = (page as unknown as Record<string, unknown>).links || (page.meta as Record<string, unknown>)?.links
48+
if (Array.isArray(links) && links.length > 0) {
49+
const linkItems = links
50+
.filter((link: { label?: string, to?: string }) => link.label && link.to)
51+
.map((link: { label: string, to: string }) => ['li', {}, ['a', { href: link.to }, link.label]])
52+
if (linkItems.length > 0) {
53+
page.body.value.push(['hr'] as unknown as MinimarkNode)
54+
page.body.value.push(['ul', {}, ...linkItems] as unknown as MinimarkNode)
55+
}
56+
}
57+
4558
setHeader(event, 'Content-Type', 'text/markdown; charset=utf-8')
4659
return stringify({ ...page.body, type: 'minimark' }, { format: 'markdown/html' })
4760
})

0 commit comments

Comments
 (0)