Skip to content

Commit 3088b3e

Browse files
Tsukiyyx990803
authored andcommitted
feat: support yaml config (#115)
1 parent 3f76bfe commit 3088b3e

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

docs/.vuepress/config.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: VuePress
3+
description: Vue-powered Static Site Generator
4+
dest: vuepress
5+
base: "/"
6+
head:
7+
- - link
8+
- rel: icon
9+
href: "/logo.png"
10+
serviceWorker: true
11+
themeConfig:
12+
repo: vuejs/vuepress
13+
editLinks: true
14+
docsDir: docs
15+
nav:
16+
- text: Guide
17+
link: "/guide/"
18+
- text: Config Reference
19+
link: "/config/"
20+
- text: Default Theme Config
21+
link: "/default-theme-config/"
22+
sidebar:
23+
"/guide/":
24+
- title: Guide
25+
collapsable: false
26+
children:
27+
- ''
28+
- getting-started
29+
- basic-config
30+
- assets
31+
- markdown
32+
- using-vue
33+
- custom-themes
34+
- deploy

lib/prepare.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const fs = require('fs-extra')
22
const path = require('path')
33
const globby = require('globby')
44
const yaml = require('yaml-front-matter')
5+
const yamlParser = require('js-yaml')
56
const tempPath = path.resolve(__dirname, 'app/.temp')
67
const { inferTitle, extractHeaders } = require('./util')
78

@@ -66,9 +67,16 @@ if (!Object.assign) Object.assign = require('object-assign')`
6667
async function resolveOptions (sourceDir) {
6768
const vuepressDir = path.resolve(sourceDir, '.vuepress')
6869
const configPath = path.resolve(vuepressDir, 'config.js')
70+
const configYmlPath = path.resolve(vuepressDir, 'config.yml')
6971

7072
delete require.cache[configPath]
71-
const siteConfig = fs.existsSync(configPath) ? require(configPath) : {}
73+
let siteConfig = {}
74+
if (fs.existsSync(configYmlPath)) {
75+
const content = await fs.readFile(configYmlPath, 'utf-8')
76+
siteConfig = yamlParser.safeLoad(content)
77+
} else if (fs.existsSync(configPath)) {
78+
siteConfig = require(configPath)
79+
}
7280

7381
// normalize description
7482
if (siteConfig.description) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"file-loader": "^1.1.11",
5757
"fs-extra": "^5.0.0",
5858
"globby": "^8.0.1",
59+
"js-yaml": "^3.11.0",
5960
"koa-connect": "^2.0.1",
6061
"koa-mount": "^3.0.0",
6162
"koa-static": "^4.0.2",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
32743274
version "3.0.2"
32753275
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
32763276

3277-
js-yaml@^3.10.0, js-yaml@^3.4.3, js-yaml@^3.9.0, js-yaml@^3.9.1:
3277+
js-yaml@^3.10.0, js-yaml@^3.11.0, js-yaml@^3.4.3, js-yaml@^3.9.0, js-yaml@^3.9.1:
32783278
version "3.11.0"
32793279
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
32803280
dependencies:

0 commit comments

Comments
 (0)