|
1 | 1 | const path = require('path')
|
2 | 2 | const fs = require('fs-extra')
|
3 | 3 | const globby = require('globby')
|
4 |
| -const yamlParser = require('js-yaml') |
5 |
| -const tomlParser = require('toml') |
6 | 4 | const createMarkdown = require('./markdown')
|
| 5 | +const loadConfig = require('./util/loadConfig') |
7 | 6 | const tempPath = path.resolve(__dirname, 'app/.temp')
|
8 | 7 | const {
|
9 | 8 | inferTitle,
|
@@ -76,21 +75,7 @@ if (!Object.assign) Object.assign = require('object-assign')`
|
76 | 75 |
|
77 | 76 | async function resolveOptions (sourceDir) {
|
78 | 77 | const vuepressDir = path.resolve(sourceDir, '.vuepress')
|
79 |
| - const configPath = path.resolve(vuepressDir, 'config.js') |
80 |
| - const configYmlPath = path.resolve(vuepressDir, 'config.yml') |
81 |
| - const configTomlPath = path.resolve(vuepressDir, 'config.toml') |
82 |
| - |
83 |
| - delete require.cache[configPath] |
84 |
| - |
85 |
| - // resolve siteConfig |
86 |
| - let siteConfig = {} |
87 |
| - if (fs.existsSync(configYmlPath)) { |
88 |
| - siteConfig = await parseConfig(configYmlPath) |
89 |
| - } else if (fs.existsSync(configTomlPath)) { |
90 |
| - siteConfig = await parseConfig(configTomlPath) |
91 |
| - } else if (fs.existsSync(configPath)) { |
92 |
| - siteConfig = require(configPath) |
93 |
| - } |
| 78 | + const siteConfig = loadConfig(vuepressDir) |
94 | 79 |
|
95 | 80 | // normalize head tag urls for base
|
96 | 81 | const base = siteConfig.base || '/'
|
@@ -361,31 +346,3 @@ function sort (arr) {
|
361 | 346 | return 0
|
362 | 347 | })
|
363 | 348 | }
|
364 |
| - |
365 |
| -async function parseConfig (file) { |
366 |
| - const content = await fs.readFile(file, 'utf-8') |
367 |
| - const [extension] = /.\w+$/.exec(file) |
368 |
| - let data |
369 |
| - |
370 |
| - switch (extension) { |
371 |
| - case '.yml': |
372 |
| - case '.yaml': |
373 |
| - data = yamlParser.safeLoad(content) |
374 |
| - break |
375 |
| - |
376 |
| - case '.toml': |
377 |
| - data = tomlParser.parse(content) |
378 |
| - // reformat to match config since TOML does not allow different data type |
379 |
| - // https://github.com/toml-lang/toml#array |
380 |
| - const format = [] |
381 |
| - Object.keys(data.head).forEach(meta => { |
382 |
| - data.head[meta].forEach(values => { |
383 |
| - format.push([meta, values]) |
384 |
| - }) |
385 |
| - }) |
386 |
| - data.head = format |
387 |
| - break |
388 |
| - } |
389 |
| - |
390 |
| - return data || {} |
391 |
| -} |
0 commit comments