@@ -99,6 +99,10 @@ export function createMarkdown(options: ResolvedOptions) {
99
99
let excerptExportsLine = ''
100
100
let excerptKeyOverlapping = false
101
101
102
+ function hasExplicitExports ( ) {
103
+ return defineExposeRE . test ( hoistScripts . scripts . map ( i => i . code ) . join ( '' ) )
104
+ }
105
+
102
106
if ( options . frontmatter ) {
103
107
if ( options . excerpt && data ) {
104
108
if ( data . excerpt !== undefined )
@@ -115,7 +119,7 @@ export function createMarkdown(options: ResolvedOptions) {
115
119
116
120
frontmatterExportsLines = Object . entries ( frontmatter ) . map ( ( [ key , value ] ) => `export const ${ key } = ${ JSON . stringify ( value ) } ` )
117
121
118
- if ( ! isVue2 && options . exposeFrontmatter && ! defineExposeRE . test ( hoistScripts . scripts . join ( '' ) ) )
122
+ if ( ! isVue2 && options . exposeFrontmatter && ! hasExplicitExports ( ) )
119
123
scriptLines . push ( 'defineExpose({ frontmatter })' )
120
124
121
125
if ( ! isVue2 && headEnabled && head ) {
@@ -131,38 +135,40 @@ export function createMarkdown(options: ResolvedOptions) {
131
135
if ( ! excerptKeyOverlapping )
132
136
excerptExportsLine = `export const excerpt = ${ JSON . stringify ( excerpt ) } \n`
133
137
134
- if ( ! isVue2 && options . exposeExcerpt && ! defineExposeRE . test ( hoistScripts . scripts . join ( '' ) ) )
138
+ if ( ! isVue2 && options . exposeExcerpt && ! hasExplicitExports ( ) )
135
139
scriptLines . push ( 'defineExpose({ excerpt })' )
136
140
}
137
141
138
142
scriptLines . push ( ...hoistScripts . scripts . map ( i => i . code ) )
139
143
140
- const attrs = uniq ( hoistScripts . scripts . map ( i => i . attr ) ) . join ( ' ' )
144
+ let attrs = uniq ( hoistScripts . scripts . map ( i => i . attr ) ) . join ( ' ' ) . trim ( )
145
+ if ( attrs )
146
+ attrs = ` ${ attrs } `
141
147
142
148
const scripts = isVue2
143
149
? [
144
- `<script ${ attrs } >` ,
150
+ `<script${ attrs } >` ,
145
151
...scriptLines ,
146
152
...frontmatterExportsLines ,
147
153
excerptExportsLine ,
148
154
'export default { data() { return { frontmatter } } }' ,
149
155
'</script>' ,
150
156
]
151
157
: [
152
- `<script setup ${ attrs } >` ,
158
+ `<script setup${ attrs } >` ,
153
159
...scriptLines ,
154
160
'</script>' ,
155
161
...( ( frontmatterExportsLines . length || excerptExportsLine )
156
162
? [
157
- `<script ${ attrs } >` ,
163
+ `<script${ attrs } >` ,
158
164
...frontmatterExportsLines ,
159
165
excerptExportsLine ,
160
166
'</script>' ,
161
167
]
162
168
: [ ] ) ,
163
169
]
164
170
165
- const sfc = `<template>${ html } </template>\n${ scripts . join ( '\n' ) } \n${ customBlocks . blocks . join ( '\n' ) } \n`
171
+ const sfc = `<template>${ html } </template>\n${ scripts . filter ( Boolean ) . join ( '\n' ) } \n${ customBlocks . blocks . join ( '\n' ) } \n`
166
172
167
173
return sfc
168
174
}
0 commit comments