Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default defineNuxtConfig({
'@nuxtjs/sitemap',
'nuxt-seo-utils',
'nuxt-og-image',
'@nuxtjs/mcp-toolkit'
'@nuxtjs/mcp-toolkit',
'nuxt-llms',
],
ignore: ['content/**'],
ui: { content: true, prose: true },
Expand Down Expand Up @@ -40,6 +41,10 @@ export default defineNuxtConfig({
},
},
nitro: {
routeRules: {
'/llms.txt': { prerender: false },
'/llms-full.txt': { prerender: false },
},
vercel: {
config: {
bypassToken: process.env.VERCEL_BYPASS_TOKEN,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"@ai-sdk/gateway": "^4.0.16",
"@ai-sdk/vue": "^4.0.22",

"@comark/nuxt": "^0.6.2",
"@iconify-json/lucide": "^1.2.120",
"@iconify-json/simple-icons": "^1.2.92",
Expand All @@ -50,11 +51,13 @@
"@vueuse/core": "^14.3.0",
"ai": "^7.0.22",
"beautiful-mermaid": "^1.1.3",

"comark": "^0.6.2",
"comark-content": "^0.3.0",
"defu": "^6.1.7",
"exsolve": "^1.1.0",
"motion-v": "^2.3.0",
"nuxt-llms": "^0.2.0",
"nuxt-og-image": "^6.7.4",
"nuxt-seo-utils": "^8.3.2",
"pathe": "^2.0.3",
Expand Down
9 changes: 8 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ export default defineNuxtConfig({
site: {
url: 'https://docs.comark.dev',
name: 'Comark Docs',
}
},
llms: {
domain: 'https://docs.comark.dev',
full: {
title: 'Full documentation',
description: 'All pages concatenated in one file',
},
},
})
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions server/plugins/llms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { appendHeader } from 'h3'
import type { NavigationItem } from 'comark-content'
import { useAppConfig } from 'nitropack/runtime'
import type { NitroApp } from 'nitropack/types'
import { joinURL } from 'ufo'
import type { LLMsSection } from 'nuxt-llms'

export default defineNitroPlugin((nitroApp: NitroApp) => {
const prerenderPaths = new Set<string>()

nitroApp.hooks.hook('llms:generate', async (event, options) => {
const content = await getProdContent()
const navigation = await content.navigation()
const site = getSiteConfig(event)
const appConfig = useAppConfig(event)
const siteName = appConfig.seo?.siteName || site.name || options.title || ''
const siteUrl = options.domain || site.url || '/'

options.title ||= siteName
options.description ||= appConfig.docs?.llms?.description || site.description || ''

const introLinks = [
{
title: 'Landing page',
description: `Overview of ${siteName}`,
href: documentLink('/', siteUrl, prerenderPaths),
},
...standaloneLinks(navigation, siteUrl, prerenderPaths),
]

options.sections.unshift({
title: 'Documentation',
description: 'Every page below is available as raw markdown. Fetch any URL directly.',
links: introLinks,
})

for (const item of navigation) {
if (!item.children?.length) continue

const links = sectionLinks(item, siteUrl, prerenderPaths)
if (!links.length) continue

options.sections.push({
title: item.title,
description: item.description,
links,
})
}

const extraLinks = (appConfig.docs?.llms?.links ?? []) as LLMsSection['links']
if (extraLinks?.length) {
options.sections.push({
title: 'Optional',
links: extraLinks,
})
}
})

nitroApp.hooks.hook('llms:generate:full', async (_event, _options, contents) => {
const content = await getProdContent()
const navigation = await content.navigation()

const paths: string[] = []
const collect = (items: NavigationItem[]) => {
for (const item of items) {
if (item.page !== false && item.path && item.path !== '/') paths.push(item.path)
if (item.children?.length) collect(item.children)
}
}
collect(navigation)

const pages = await Promise.all(
[...new Set(paths)].map((path) => renderPageMarkdown(content, path))
)
contents.push(...pages.filter((page): page is string => Boolean(page)))
})

if (['nitro-prerender', 'nitro-dev'].includes(import.meta.preset as string)) {
nitroApp.hooks.hook('beforeResponse', (event) => {
if (event.path === '/') {
appendHeader(event, 'x-nitro-prerender', Array.from(prerenderPaths))
}
})
}
})

function standaloneLinks(
navigation: NavigationItem[],
siteUrl: string,
prerenderPaths: Set<string>
): NonNullable<LLMsSection['links']> {
return navigation
.filter((item) => !item.children?.length && item.page !== false && item.path && item.path !== '/')
.map((item) => ({
title: item.title,
description: item.description,
href: documentLink(item.path, siteUrl, prerenderPaths),
}))
}

function sectionLinks(
item: NavigationItem,
siteUrl: string,
prerenderPaths: Set<string>
): NonNullable<LLMsSection['links']> {
const links: NonNullable<LLMsSection['links']> = []

const collect = (items: NavigationItem[]) => {
for (const entry of items) {
if (entry.page !== false && entry.path && entry.path !== '/') {
links.push({
title: entry.title,
description: entry.description,
href: documentLink(entry.path, siteUrl, prerenderPaths),
})
}
if (entry.children?.length) collect(entry.children)
}
}

if (item.page !== false && item.path && item.path !== '/') {
links.push({
title: item.title,
description: item.description,
href: documentLink(item.path, siteUrl, prerenderPaths),
})
}

if (item.children?.length) collect(item.children)

return links
}

function documentLink(path: string, domain: string, prerenderPaths: Set<string>) {
const href = joinURL(domain, rawUrlForPage(path))
prerenderPaths.add(rawUrlForPage(path))
return href
}
23 changes: 0 additions & 23 deletions server/routes/llms-full.txt.get.ts

This file was deleted.

52 changes: 0 additions & 52 deletions server/routes/llms.txt.get.ts

This file was deleted.

Loading