@@ -2,6 +2,7 @@ const path = require('path')
22const fs = require ( 'fs-extra' )
33const globby = require ( 'globby' )
44const yamlParser = require ( 'js-yaml' )
5+ const tomlParser = require ( 'toml' )
56const yaml = require ( 'yaml-front-matter' )
67const createMarkdown = require ( './markdown' )
78const tempPath = path . resolve ( __dirname , 'app/.temp' )
@@ -69,12 +70,14 @@ async function resolveOptions (sourceDir) {
6970 const vuepressDir = path . resolve ( sourceDir , '.vuepress' )
7071 const configPath = path . resolve ( vuepressDir , 'config.js' )
7172 const configYmlPath = path . resolve ( vuepressDir , 'config.yml' )
73+ const configTomlPath = path . resolve ( vuepressDir , 'config.toml' )
7274
7375 delete require . cache [ configPath ]
7476 let siteConfig = { }
7577 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 )
7881 } else if ( fs . existsSync ( configPath ) ) {
7982 siteConfig = require ( configPath )
8083 }
@@ -283,3 +286,31 @@ function sort (arr) {
283286 return 0
284287 } )
285288}
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