-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract inline plugin templates as independent files (#1874)
* refactor: mv to tmpl * refactor: more info * refactor: to template * docs: add customize page * refactor: to contant * chore: revert config * chore: rm tmpl * chore: dir path * chore: clean up
- Loading branch information
Showing
9 changed files
with
145 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Customize Page for dumi test | ||
export default () => 'Customize Dumi Test Page'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import { useOutlet, history } from 'dumi'; | ||
import { SiteContext } from '{{{contextPath}}}'; | ||
import { demos, components } from '../meta'; | ||
import { locales } from '../locales/config'; | ||
{{{defaultExport}}} | ||
{{{namedExport}}} | ||
|
||
const entryExports = { | ||
{{#hasDefaultExport}} | ||
default: entryDefaultExport, | ||
{{/hasDefaultExport}} | ||
{{#hasNamedExport}} | ||
...entryMemberExports, | ||
{{/hasNamedExport}} | ||
}; | ||
|
||
export default function DumiContextWrapper() { | ||
const outlet = useOutlet(); | ||
const [loading, setLoading] = useState(false); | ||
const prev = useRef(history.location.pathname); | ||
useEffect(() => { | ||
return history.listen((next) => { | ||
if (next.location.pathname !== prev.current) { | ||
prev.current = next.location.pathname; | ||
// scroll to top when route changed | ||
document.documentElement.scrollTo(0, 0); | ||
} | ||
}); | ||
}, []); | ||
|
||
const context = { | ||
pkg: {{{pkg}}}, | ||
historyType: "{{{historyType}}}", | ||
entryExports, | ||
demos, | ||
components, | ||
locales, | ||
loading, | ||
setLoading, | ||
hostname: {{{hostname}}}, | ||
themeConfig: {{{themeConfig}}}, | ||
_2_level_nav_available: {{{_2_level_nav_available}}}, | ||
}; | ||
|
||
return ( | ||
<SiteContext.Provider value={context}> | ||
{outlet} | ||
</SiteContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{{#metaFiles}} | ||
import { demos as dm{{{index}}}, frontmatter as fm{{{index}}}, toc as toc{{{index}}}, texts as txt{{{index}}} } from '{{{file}}}?type=meta'; | ||
{{/metaFiles}} | ||
|
||
export { components } from './atoms'; | ||
export { tabs } from './tabs'; | ||
|
||
export const filesMeta = { | ||
{{#metaFiles}} | ||
'{{{id}}}': { | ||
frontmatter: fm{{{index}}}, | ||
toc: toc{{{index}}}, | ||
texts: txt{{{index}}}, | ||
demos: dm{{{index}}}, | ||
{{#tabs}} | ||
tabs: {{{tabs}}}, | ||
{{/tabs}} | ||
}, | ||
{{/metaFiles}} | ||
} | ||
|
||
// generate demos data in runtime, for reuse route.id to reduce bundle size | ||
export const demos = Object.entries(filesMeta).reduce((acc, [id, meta]) => { | ||
// append route id to demo | ||
Object.values(meta.demos).forEach((demo) => { | ||
demo.routeId = id; | ||
}); | ||
// merge demos | ||
Object.assign(acc, meta.demos); | ||
|
||
// remove demos from meta, to avoid deep clone demos in umi routes/children compatible logic | ||
delete meta.demos; | ||
|
||
return acc; | ||
}, {}); |