mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 00:47:03 +02:00
refactor: load theme
This commit is contained in:
parent
10b1a38762
commit
828d99dc8e
2 changed files with 22 additions and 14 deletions
|
@ -1,8 +1,8 @@
|
||||||
const fs = require('fs-extra');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const loadConfig = require('./config');
|
const loadConfig = require('./config');
|
||||||
const loadDocs = require('./docs');
|
const loadDocs = require('./docs');
|
||||||
const loadPages = require('./pages');
|
const loadPages = require('./pages');
|
||||||
|
const loadTheme = require('./theme');
|
||||||
const {generate} = require('./utils');
|
const {generate} = require('./utils');
|
||||||
const genRoutesConfig = require('./routes');
|
const genRoutesConfig = require('./routes');
|
||||||
|
|
||||||
|
@ -34,19 +34,7 @@ module.exports = async function load(siteDir) {
|
||||||
const outDir = path.resolve(siteDir, 'build');
|
const outDir = path.resolve(siteDir, 'build');
|
||||||
|
|
||||||
// resolve the theme
|
// resolve the theme
|
||||||
const customThemePath = path.resolve(siteDir, 'theme');
|
const themePath = loadTheme(siteDir);
|
||||||
const themePath = fs.existsSync(customThemePath)
|
|
||||||
? customThemePath
|
|
||||||
: path.resolve(__dirname, '../theme');
|
|
||||||
|
|
||||||
const themeComponents = ['Docs', 'Loading', 'NotFound'];
|
|
||||||
themeComponents.forEach(component => {
|
|
||||||
if (!require.resolve(path.join(themePath, component))) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to load ${themePath}/${component}. It does not exist.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const baseUrl = siteConfig.baseUrl || '/';
|
const baseUrl = siteConfig.baseUrl || '/';
|
||||||
|
|
||||||
|
|
20
lib/load/theme.js
Normal file
20
lib/load/theme.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = function loadConfig(siteDir) {
|
||||||
|
const customThemePath = path.resolve(siteDir, 'theme');
|
||||||
|
const themePath = fs.existsSync(customThemePath)
|
||||||
|
? customThemePath
|
||||||
|
: path.resolve(__dirname, '../theme');
|
||||||
|
|
||||||
|
const themeComponents = ['Docs', 'Loading', 'NotFound'];
|
||||||
|
themeComponents.forEach(component => {
|
||||||
|
if (!require.resolve(path.join(themePath, component))) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to load ${themePath}/${component}. It does not exist.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return themePath;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue