mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-09 05:16:23 +10:00
refactor: root mixins injection (#423)
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
export function injectMixins (options, mixins) {
|
||||
if (!options.mixins) {
|
||||
options.mixins = []
|
||||
}
|
||||
options.mixins.push(...mixins)
|
||||
}
|
||||
|
||||
export function pathToComponentName (path) {
|
||||
if (path.charAt(path.length - 1) === '/') {
|
||||
return `page${path.replace(/\//g, '-') + 'index'}`
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
/* eslint-disable */
|
||||
import rootMixins from '@app/root-mixins'
|
||||
function injectRootMixins (options) {
|
||||
if (!options.mixins) {
|
||||
options.mixins = []
|
||||
}
|
||||
options.mixins.push(...rootMixins)
|
||||
}
|
||||
+5
-6
@@ -342,14 +342,13 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
|
||||
component: ThemeNotFound
|
||||
}`
|
||||
|
||||
const injectRootMixins = await fs.readFile(path.resolve(__dirname, 'code/injectRootMixins.js'), 'utf-8')
|
||||
|
||||
return (
|
||||
`import ThemeLayout from '@themeLayout'\n` +
|
||||
`import ThemeNotFound from '@themeNotFound'\n\n` +
|
||||
`${injectRootMixins}\n` +
|
||||
`injectRootMixins(ThemeLayout)\n` +
|
||||
`injectRootMixins(ThemeNotFound)\n\n` +
|
||||
`import ThemeNotFound from '@themeNotFound'\n` +
|
||||
`import { injectMixins } from '@app/util'\n` +
|
||||
`import rootMixins from '@app/root-mixins'\n\n` +
|
||||
`injectMixins(ThemeLayout, rootMixins)\n` +
|
||||
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
|
||||
`export const routes = [${pages.map(genRoute).join(',')}${notFoundRoute}\n]`
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user