1- import type { MDCElement } from '@nuxtjs/mdc'
1+ import type { MDCElement , MDCRoot } from '@nuxtjs/mdc'
22import { withBase } from 'ufo'
33import { pascalCase } from 'scule'
44import type { LLMsSection } from 'nuxt-llms'
@@ -19,17 +19,15 @@ export interface ContentLLMSCollectionSection extends LLMsSection {
1919
2020const linkProps = [ 'href' , 'src' , 'to' ]
2121
22- const importExternalPackage = async ( name : string ) => await import ( name )
23-
2422export async function createDocumentGenerator ( ) {
25- const visit = await importExternalPackage ( 'unist-util-visit' ) . then ( res => res . visit )
26- const stringifyMarkdown = await importExternalPackage ( '@nuxtjs/mdc/runtime' ) . then ( res => res . stringifyMarkdown )
23+ const { visit } = await import ( 'unist-util-visit' )
24+ const { stringifyMarkdown } = await import ( '@nuxtjs/mdc/runtime' )
2725
2826 return generateDocument
2927
3028 async function generateDocument ( doc : PageCollectionItemBase , options : { domain : string } ) {
3129 const hastTree = refineDocumentBody ( doc . body as unknown as MinimarkTree , options )
32- let markdown = await stringifyMarkdown ( hastTree , { } )
30+ let markdown = await stringifyMarkdown ( hastTree as unknown as MDCRoot , { } )
3331
3432 if ( ! markdown ?. trim ( ) . startsWith ( '# ' ) ) {
3533 const title = doc . title || doc . seo ?. title || ''
@@ -43,10 +41,14 @@ export async function createDocumentGenerator() {
4341 function refineDocumentBody ( body : MinimarkTree , options : { domain : string } ) {
4442 const hastTree = toHast ( body )
4543
46- visit ( hastTree , ( node : MDCElement ) => ! ! node . props ?. to || ! ! node . props ?. href || ! ! node . props ?. src , ( node : MDCElement ) => {
44+ visit ( hastTree , ( node ) => {
45+ const el = node as unknown as MDCElement
46+ if ( ! el . props ?. to && ! el . props ?. href && ! el . props ?. src ) {
47+ return
48+ }
4749 for ( const prop of linkProps ) {
48- if ( node . props ?. [ prop ] ) {
49- node . props [ prop ] = withBase ( node . props [ prop ] , options . domain )
50+ if ( el . props ?. [ prop ] ) {
51+ el . props [ prop ] = withBase ( el . props [ prop ] , options . domain )
5052 }
5153 }
5254 } )
0 commit comments