@@ -19,17 +19,24 @@ export default defineConfig({
19
19
basePath ,
20
20
'*/demos/**/*.{[tj]sx,md?(x)}' ,
21
21
async function fileHandler ( file , api ) {
22
- const { relative, path : absolute } = file
22
+ const { relative, path : demoFilePath } = file
23
23
const match = relative . match (
24
24
/ ( .* ) \/ d e m o s \/ ( .* ) \. ( [ t j ] s x | m d x ? ) $ /
25
25
)
26
- if ( ! match ) throw new Error ( 'unexpected file: ' + absolute )
26
+ if ( ! match ) throw new Error ( 'unexpected file: ' + demoFilePath )
27
27
const [ _ , componentName , demoName ] = match
28
28
const pageId = `/components/demos/${ componentName } `
29
- // set page data
30
- const runtimeDataPaths = api . getRuntimeData ( pageId )
31
- // the ?demo query will wrap the module with useful demoInfo
32
- runtimeDataPaths [ demoName ] = `${ absolute } ?demo`
29
+ // register page data
30
+ api . addPageData ( {
31
+ pageId,
32
+ key : demoName ,
33
+ // register demo runtime data path
34
+ // it will be consumed by theme-doc
35
+ // the ?demo query will wrap the module with useful demoInfo
36
+ dataPath : `${ demoFilePath } ?demo` ,
37
+ // register demo static data
38
+ staticData : await helpers . extractStaticData ( file ) ,
39
+ } )
33
40
}
34
41
)
35
42
}
@@ -39,17 +46,28 @@ export default defineConfig({
39
46
basePath ,
40
47
'*/README.md?(x)' ,
41
48
async function fileHandler ( file , api ) {
42
- const { relative, path : absolute } = file
49
+ const { relative, path : markdownFilePath } = file
43
50
const match = relative . match ( / ( .* ) \/ R E A D M E \. m d x ? $ / )
44
- if ( ! match ) throw new Error ( 'unexpected file: ' + absolute )
51
+ if ( ! match )
52
+ throw new Error ( 'unexpected file: ' + markdownFilePath )
45
53
const [ _ , componentName ] = match
46
54
const pageId = `/components/${ componentName } `
47
- // set page data
48
- const runtimeDataPaths = api . getRuntimeData ( pageId )
49
- runtimeDataPaths . main = absolute
50
- // set page staticData
51
- const staticData = api . getStaticData ( pageId )
52
- staticData . main = await helpers . extractStaticData ( file )
55
+ // register page data
56
+ api . addPageData ( {
57
+ pageId,
58
+ // register page component
59
+ dataPath : markdownFilePath ,
60
+ // register static data
61
+ staticData : await helpers . extractStaticData ( file ) ,
62
+ } )
63
+ // register outlineInfo data
64
+ // it will be consumed by theme-doc
65
+ api . addPageData ( {
66
+ pageId,
67
+ key : 'outlineInfo' ,
68
+ // the ?outlineInfo query will extract title info from the markdown file and return the data as a js module
69
+ dataPath : `${ markdownFilePath } ?outlineInfo` ,
70
+ } )
53
71
}
54
72
)
55
73
} ,
0 commit comments