Skip to content

Commit

Permalink
feat: support yaml config (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuki authored and yyx990803 committed Apr 18, 2018
1 parent 3f76bfe commit 3088b3e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
34 changes: 34 additions & 0 deletions docs/.vuepress/config.yml
@@ -0,0 +1,34 @@
---
title: VuePress
description: Vue-powered Static Site Generator
dest: vuepress
base: "/"
head:
- - link
- rel: icon
href: "/logo.png"
serviceWorker: true
themeConfig:
repo: vuejs/vuepress
editLinks: true
docsDir: docs
nav:
- text: Guide
link: "/guide/"
- text: Config Reference
link: "/config/"
- text: Default Theme Config
link: "/default-theme-config/"
sidebar:
"/guide/":
- title: Guide
collapsable: false
children:
- ''
- getting-started
- basic-config
- assets
- markdown
- using-vue
- custom-themes
- deploy
10 changes: 9 additions & 1 deletion lib/prepare.js
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs-extra')
const path = require('path')
const globby = require('globby')
const yaml = require('yaml-front-matter')
const yamlParser = require('js-yaml')
const tempPath = path.resolve(__dirname, 'app/.temp')
const { inferTitle, extractHeaders } = require('./util')

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

delete require.cache[configPath]
const siteConfig = fs.existsSync(configPath) ? require(configPath) : {}
let siteConfig = {}
if (fs.existsSync(configYmlPath)) {
const content = await fs.readFile(configYmlPath, 'utf-8')
siteConfig = yamlParser.safeLoad(content)
} else if (fs.existsSync(configPath)) {
siteConfig = require(configPath)
}

// normalize description
if (siteConfig.description) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -56,6 +56,7 @@
"file-loader": "^1.1.11",
"fs-extra": "^5.0.0",
"globby": "^8.0.1",
"js-yaml": "^3.11.0",
"koa-connect": "^2.0.1",
"koa-mount": "^3.0.0",
"koa-static": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -3274,7 +3274,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

js-yaml@^3.10.0, js-yaml@^3.4.3, js-yaml@^3.9.0, js-yaml@^3.9.1:
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:
version "3.11.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
dependencies:
Expand Down

0 comments on commit 3088b3e

Please sign in to comment.