Files
2025-08-16 12:32:49 +02:00

32 lines
1014 B
TypeScript

import type { H3Event } from 'h3'
import type { PageCollectionItemBase } from '@nuxt/content'
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('content:llms:generate:document', async (_: H3Event, doc: PageCollectionItemBase) => {
transformMDC(doc as any)
})
nitroApp.hooks.hook('llms:generate', (_, { sections }) => {
// Transform links except for "Documentation Sets"
sections.forEach((section) => {
if (section.title !== 'Documentation Sets') {
section.links = section.links.map(link => ({
...link,
href: transformRawLink(link.href)
}))
}
})
// Move "Documentation Sets" to the end
const docSetIdx = sections.findIndex(s => s.title === 'Documentation Sets')
if (docSetIdx !== -1) {
const [docSet] = sections.splice(docSetIdx, 1)
sections.push(docSet)
}
})
})
function transformRawLink(href: string) {
return `${href.replace(/^https:\/\/ui4.nuxt.com/, 'https://ui4.nuxt.com/raw')}.md`
}