Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:support yaml config #115

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/.vuepress/config.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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