@@ -2,6 +2,7 @@ const path = require('path')
2
2
const fs = require ( 'fs-extra' )
3
3
const globby = require ( 'globby' )
4
4
const yamlParser = require ( 'js-yaml' )
5
+ const tomlParser = require ( 'toml' )
5
6
const yaml = require ( 'yaml-front-matter' )
6
7
const createMarkdown = require ( './markdown' )
7
8
const tempPath = path . resolve ( __dirname , 'app/.temp' )
@@ -69,12 +70,14 @@ async function resolveOptions (sourceDir) {
69
70
const vuepressDir = path . resolve ( sourceDir , '.vuepress' )
70
71
const configPath = path . resolve ( vuepressDir , 'config.js' )
71
72
const configYmlPath = path . resolve ( vuepressDir , 'config.yml' )
73
+ const configTomlPath = path . resolve ( vuepressDir , 'config.toml' )
72
74
73
75
delete require . cache [ configPath ]
74
76
let siteConfig = { }
75
77
if ( fs . existsSync ( configYmlPath ) ) {
76
- const content = await fs . readFile ( configYmlPath , 'utf-8' )
77
- siteConfig = yamlParser . safeLoad ( content )
78
+ siteConfig = await parseConfig ( configYmlPath )
79
+ } else if ( fs . existsSync ( configTomlPath ) ) {
80
+ siteConfig = await parseConfig ( configTomlPath )
78
81
} else if ( fs . existsSync ( configPath ) ) {
79
82
siteConfig = require ( configPath )
80
83
}
@@ -283,3 +286,31 @@ function sort (arr) {
283
286
return 0
284
287
} )
285
288
}
289
+
290
+ async function parseConfig ( file ) {
291
+ const content = await fs . readFile ( file , 'utf-8' )
292
+ const [ extension ] = / .\w + $ / . exec ( file )
293
+ let data
294
+
295
+ switch ( extension ) {
296
+ case '.yml' :
297
+ case '.yaml' :
298
+ data = yamlParser . safeLoad ( content )
299
+ break
300
+
301
+ case '.toml' :
302
+ data = tomlParser . parse ( content )
303
+ // reformat to match config since TOML does not allow different data type
304
+ // https://github.com/toml-lang/toml#array
305
+ const format = [ ]
306
+ Object . keys ( data . head ) . forEach ( meta => {
307
+ data . head [ meta ] . forEach ( values => {
308
+ format . push ( [ meta , values ] )
309
+ } )
310
+ } )
311
+ data . head = format
312
+ break
313
+ }
314
+
315
+ return data || { }
316
+ }
0 commit comments