1
+ import { onBeforeUnmount } from 'vue'
2
+
1
3
type ExampleData = {
2
4
[ key : string ] : Record < string , string >
3
5
} & {
@@ -66,7 +68,7 @@ function forEachComponent(
66
68
) {
67
69
for ( const filename in raw ) {
68
70
const content = raw [ filename ]
69
- if ( filename === 'description.txt' ) {
71
+ if ( filename === 'description.txt' || filename === 'description.md' ) {
70
72
continue
71
73
} else if ( typeof content === 'string' ) {
72
74
files [ filename ] = content
@@ -93,14 +95,18 @@ function injectCreateApp(src: string): string {
93
95
return src . replace ( / e x p o r t d e f a u l t ( { [ ^ ] * \n } ) / , "createApp(1γγ«).mount('#app')" )
94
96
}
95
97
96
- export function resolveSFCExample ( raw : ExampleData , preferComposition : boolean ) {
98
+ export function resolveSFCExample (
99
+ raw : ExampleData ,
100
+ preferComposition : boolean
101
+ ) {
97
102
const files : Record < string , string > = { }
98
103
forEachComponent (
99
104
raw ,
100
105
files ,
101
106
( filename , { template, composition, options, style } ) => {
107
+ const desc = raw [ 'description.txt' ]
102
108
let sfcContent =
103
- filename === 'App' ? `<!--\n${ raw [ 'description.txt' ] } \n-->\n\n` : ``
109
+ desc && filename === 'App' ? `<!--\n${ desc } \n-->\n\n` : ``
104
110
if ( preferComposition ) {
105
111
sfcContent += `<script setup>\n${ toScriptSetup (
106
112
composition ,
@@ -119,10 +125,14 @@ export function resolveSFCExample(raw: ExampleData, preferComposition: boolean)
119
125
return files
120
126
}
121
127
122
- export function resolveNoBuildExample ( raw : ExampleData , preferComposition : boolean ) {
128
+ export function resolveNoBuildExample (
129
+ raw : ExampleData ,
130
+ preferComposition : boolean
131
+ ) {
123
132
const files : Record < string , string > = { }
124
133
125
- let html = `<!--\n${ raw [ 'description.txt' ] } \n-->\n\n`
134
+ const desc = raw [ 'description.txt' ]
135
+ let html = desc ? `<!--\n${ desc } )}\n-->\n\n` : ``
126
136
let css = ''
127
137
128
138
// set it first for ordering
@@ -140,7 +150,7 @@ export function resolveNoBuildExample(raw: ExampleData, preferComposition: boole
140
150
141
151
if ( filename === 'App' ) {
142
152
html += `<script type="module">\n${ injectCreateApp ( js ) } <\/script>`
143
- html += `\n\n<div id="app">\n${ _template } </div>`
153
+ html += `\n\n<div id="app">\n${ _template } \n </div>`
144
154
} else {
145
155
// html += `\n\n<template id="${filename}">\n${_template}</template>`
146
156
js = js . replace (
@@ -158,4 +168,9 @@ export function resolveNoBuildExample(raw: ExampleData, preferComposition: boole
158
168
return files
159
169
}
160
170
161
-
171
+ export function onHashChange ( cb ) {
172
+ window . addEventListener ( 'hashchange' , cb )
173
+ onBeforeUnmount ( ( ) => {
174
+ window . removeEventListener ( 'hashchange' , cb )
175
+ } )
176
+ }
0 commit comments