@@ -11,13 +11,36 @@ async function getDemoList() {
11
11
. map ( filename => filename . slice ( 0 , - 4 ) )
12
12
}
13
13
14
+ async function getFiles ( demo ) {
15
+ let filenames = [ ]
16
+ try {
17
+ filenames = await fs . promises . readdir (
18
+ `./content/${ demo } /`
19
+ )
20
+ } catch ( e ) {
21
+ return undefined
22
+ }
23
+
24
+ const files = { }
25
+ for ( const filename of filenames ) {
26
+ files [ filename ] = await fs . promises . readFile (
27
+ `./content/${ demo } /${ filename } ` ,
28
+ "utf8"
29
+ )
30
+ }
31
+
32
+ return files
33
+ }
34
+
14
35
export async function toProps ( { demo, theme } ) {
15
36
const mdxSource = await fs . promises . readFile (
16
37
`./content/${ demo } .mdx` ,
17
38
"utf8"
18
39
)
19
40
20
- const preCodeHike = await bundle ( mdxSource , [
41
+ const files = await getFiles ( demo )
42
+
43
+ const preCodeHike = await bundle ( mdxSource , files , [
21
44
remarkShowTree ,
22
45
] )
23
46
@@ -27,12 +50,12 @@ export async function toProps({ demo, theme }) {
27
50
`shiki/themes/${ theme } .json`
28
51
) . then ( module => module . default )
29
52
30
- postCodeHike = await bundle ( mdxSource , [
53
+ postCodeHike = await bundle ( mdxSource , files , [
31
54
[ remarkCodeHike , { theme : loadedTheme } ] ,
32
55
remarkShowTree ,
33
56
] )
34
57
35
- result = await bundle ( mdxSource , [
58
+ result = await bundle ( mdxSource , files , [
36
59
[ remarkCodeHike , { theme : loadedTheme } ] ,
37
60
] )
38
61
} catch ( e ) {
@@ -70,8 +93,9 @@ export async function toProps({ demo, theme }) {
70
93
}
71
94
}
72
95
73
- async function bundle ( source , plugins ) {
96
+ async function bundle ( source , files , plugins ) {
74
97
const { code } = await bundleMDX ( source , {
98
+ files,
75
99
esbuildOptions ( options ) {
76
100
options . minify = false
77
101
options . platform = "node"
0 commit comments