|
| 1 | +import type { H3Event } from 'h3' |
1 | 2 | import json5 from 'json5' |
2 | 3 | import { camelCase, kebabCase } from 'scule' |
3 | 4 | import { visit } from '@nuxt/content/runtime' |
| 5 | +import { queryCollection } from '@nuxt/content/server' |
4 | 6 | import * as theme from '../../.nuxt/ui' |
5 | 7 | import meta from '#nuxt-component-meta' |
6 | 8 | // @ts-expect-error - no types available |
@@ -291,7 +293,7 @@ const generateComponentCode = ({ |
291 | 293 | </template>` |
292 | 294 | } |
293 | 295 |
|
294 | | -export function transformMDC(doc: Document): Document { |
| 296 | +export async function transformMDC(event: H3Event, doc: Document): Promise<Document> { |
295 | 297 | const componentName = camelCase(doc.title) |
296 | 298 |
|
297 | 299 | visitAndReplace(doc, 'component-theme', (node) => { |
@@ -394,5 +396,31 @@ export function transformMDC(doc: Document): Document { |
394 | 396 | replaceNodeWithPre(node, 'vue', code, `${name}.vue`) |
395 | 397 | }) |
396 | 398 |
|
| 399 | + const componentsListNodes: any[] = [] |
| 400 | + visit(doc.body, (node) => { |
| 401 | + if (Array.isArray(node) && node[0] === 'components-list') { |
| 402 | + componentsListNodes.push(node) |
| 403 | + } |
| 404 | + return true |
| 405 | + }, node => node) |
| 406 | + |
| 407 | + for (const node of componentsListNodes) { |
| 408 | + const category = node[1]?.category |
| 409 | + if (!category) continue |
| 410 | + |
| 411 | + const components = await queryCollection(event, 'docs') |
| 412 | + .where('path', 'LIKE', '/docs/components/%') |
| 413 | + .where('extension', '=', 'md') |
| 414 | + .where('category', '=', category) |
| 415 | + .select('path', 'title') |
| 416 | + .all() |
| 417 | + |
| 418 | + const links = components.map((c: any) => `- [${c.title}](https://ui.nuxt.com${c.path})`).join('\n') |
| 419 | + |
| 420 | + node[0] = 'p' |
| 421 | + node[1] = {} |
| 422 | + node[2] = links |
| 423 | + } |
| 424 | + |
397 | 425 | return doc |
398 | 426 | } |
0 commit comments