Skip to content

Commit d83fa69

Browse files
committedMay 29, 2017
fix: path => context
1 parent 1227451 commit d83fa69

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed
 

‎lib/commands/start.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,51 @@ var defaultConfig = {
2222
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
2323
</body>
2424
</html>`,
25-
path: './'
25+
context: './'
2626
}
2727

2828
function loadConfig (config) {
2929
try {
3030
return require(util.cwd(config))
3131
} catch (e) {
32-
console.log(chalk.red(`Not found ${config}`))
32+
console.log(chalk.red(`${e.message} in ${config}`))
3333
process.exit(1)
3434
}
3535
}
3636

3737
module.exports = function (path, configFile, port) {
3838
let config = defaultConfig
3939
const pkg = util.pkg()
40+
let ctx = util.cwd()
41+
42+
path = path || './'
4043

4144
if (configFile) {
4245
config = loadConfig(configFile)
46+
ctx = config.context || ctx
47+
config.template = /\.html$/.test(config.template)
48+
? util.read(util.resolve(ctx, config.template))
49+
: config.template
4350
} else if (pkg.docsify) {
4451
config = pkg.docsify
45-
config.template = util.exists(util.cwd(pkg.docsify.template))
52+
config.template = util.exists(util.resolve(ctx, pkg.docsify.template))
4653
? util(pkg.docsify.template)
4754
: defaultConfig.template
4855
}
4956

50-
var renderer = new Renderer(config)
57+
var renderer = new Renderer(Object.assign(defaultConfig, config))
5158
var server = connect()
5259

5360
server.use(function(req, res) {
5461
renderer.renderToString(req.url)
55-
.then(res.end(html))
56-
.catch(res.end(util.read(util.resolve(path, 'index.html'))))
62+
.then(function (html) {
63+
res.end(html)
64+
})
65+
.catch(function (err) {
66+
res.end(util.read(util.resolve(path, 'index.html')))
67+
})
5768
})
58-
server.use(serveStatic(path || '.'))
69+
server.use(serveStatic(path))
5970
server.listen(port || 4000)
6071

6172
const msg = '\n'

‎lib/util/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require('fs')
55
var resolve = exports.resolve = require('path').resolve
66

77
exports.cwd = function (path) {
8-
return resolve(process.cwd(), path)
8+
return resolve(process.cwd(), path || '.')
99
}
1010

1111
exports.pwd = function (path) {

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"connect-livereload": "^0.6.0",
3333
"cp-file": "^4.1.1",
3434
"docsify": ">=3",
35+
"docsify-server-renderer": "^4.0.0",
3536
"fs-extra": "^2.1.2",
3637
"livereload": "^0.6.2",
3738
"open": "^0.0.5",

0 commit comments

Comments
 (0)
Please sign in to comment.