Skip to content

Commit 016cf6f

Browse files
committed
fix(create-project): improve templates
1 parent 708440c commit 016cf6f

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

packages/create-project/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-vite-pages",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"keywords": [
55
"vite",
66
"react",

packages/create-project/template-lib-monorepo/packages/demos/vite.config.ts

+32-14
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ export default defineConfig({
1919
basePath,
2020
'*/demos/**/*.{[tj]sx,md?(x)}',
2121
async function fileHandler(file, api) {
22-
const { relative, path: absolute } = file
22+
const { relative, path: demoFilePath } = file
2323
const match = relative.match(
2424
/(.*)\/demos\/(.*)\.([tj]sx|mdx?)$/
2525
)
26-
if (!match) throw new Error('unexpected file: ' + absolute)
26+
if (!match) throw new Error('unexpected file: ' + demoFilePath)
2727
const [_, componentName, demoName] = match
2828
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+
})
3340
}
3441
)
3542
}
@@ -39,17 +46,28 @@ export default defineConfig({
3946
basePath,
4047
'*/README.md?(x)',
4148
async function fileHandler(file, api) {
42-
const { relative, path: absolute } = file
49+
const { relative, path: markdownFilePath } = file
4350
const match = relative.match(/(.*)\/README\.mdx?$/)
44-
if (!match) throw new Error('unexpected file: ' + absolute)
51+
if (!match)
52+
throw new Error('unexpected file: ' + markdownFilePath)
4553
const [_, componentName] = match
4654
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+
})
5371
}
5472
)
5573
},

packages/create-project/template-lib/docs/vite.config.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ export default defineConfig({
1818
srcPath,
1919
'*/demos/**/*.{[tj]sx,md?(x)}',
2020
async function fileHandler(file, api) {
21-
const { relative, path: absolute } = file
21+
const { relative, path: demoFilePath } = file
2222
const match = relative.match(
2323
/(.*)\/demos\/(.*)\.([tj]sx|mdx?)$/
2424
)
25-
if (!match) throw new Error('unexpected file: ' + absolute)
25+
if (!match) throw new Error('unexpected file: ' + demoFilePath)
2626
const [_, componentName, demoName] = match
2727
const pageId = `/components/demos/${componentName}`
2828
// register page data
2929
api.addPageData({
3030
pageId,
3131
key: demoName,
3232
// register demo runtime data path
33+
// it will be consumed by theme-doc
3334
// the ?demo query will wrap the module with useful demoInfo
34-
// that will be consumed by theme-doc
35-
dataPath: `${absolute}?demo`,
35+
dataPath: `${demoFilePath}?demo`,
3636
// register demo static data
3737
staticData: await helpers.extractStaticData(file),
3838
})
@@ -45,19 +45,28 @@ export default defineConfig({
4545
srcPath,
4646
'*/README.md?(x)',
4747
async function fileHandler(file, api) {
48-
const { relative, path: absolute } = file
48+
const { relative, path: markdownFilePath } = file
4949
const match = relative.match(/(.*)\/README\.mdx?$/)
50-
if (!match) throw new Error('unexpected file: ' + absolute)
50+
if (!match)
51+
throw new Error('unexpected file: ' + markdownFilePath)
5152
const [_, componentName] = match
5253
const pageId = `/components/${componentName}`
5354
// register page data
5455
api.addPageData({
5556
pageId,
56-
// register demo runtime data path
57-
dataPath: absolute,
58-
// register demo static data
57+
// register page component
58+
dataPath: markdownFilePath,
59+
// register static data
5960
staticData: await helpers.extractStaticData(file),
6061
})
62+
// register outlineInfo data
63+
// it will be consumed by theme-doc
64+
api.addPageData({
65+
pageId,
66+
key: 'outlineInfo',
67+
// the ?outlineInfo query will extract title info from the markdown file and return the data as a js module
68+
dataPath: `${markdownFilePath}?outlineInfo`,
69+
})
6170
}
6271
)
6372
},

0 commit comments

Comments
 (0)