@@ -22,40 +22,51 @@ var defaultConfig = {
22
22
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
23
23
</body>
24
24
</html>` ,
25
- path : './'
25
+ context : './'
26
26
}
27
27
28
28
function loadConfig ( config ) {
29
29
try {
30
30
return require ( util . cwd ( config ) )
31
31
} catch ( e ) {
32
- console . log ( chalk . red ( `Not found ${ config } ` ) )
32
+ console . log ( chalk . red ( `${ e . message } in ${ config } ` ) )
33
33
process . exit ( 1 )
34
34
}
35
35
}
36
36
37
37
module . exports = function ( path , configFile , port ) {
38
38
let config = defaultConfig
39
39
const pkg = util . pkg ( )
40
+ let ctx = util . cwd ( )
41
+
42
+ path = path || './'
40
43
41
44
if ( configFile ) {
42
45
config = loadConfig ( configFile )
46
+ ctx = config . context || ctx
47
+ config . template = / \. h t m l $ / . test ( config . template )
48
+ ? util . read ( util . resolve ( ctx , config . template ) )
49
+ : config . template
43
50
} else if ( pkg . docsify ) {
44
51
config = pkg . docsify
45
- config . template = util . exists ( util . cwd ( pkg . docsify . template ) )
52
+ config . template = util . exists ( util . resolve ( ctx , pkg . docsify . template ) )
46
53
? util ( pkg . docsify . template )
47
54
: defaultConfig . template
48
55
}
49
56
50
- var renderer = new Renderer ( config )
57
+ var renderer = new Renderer ( Object . assign ( defaultConfig , config ) )
51
58
var server = connect ( )
52
59
53
60
server . use ( function ( req , res ) {
54
61
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
+ } )
57
68
} )
58
- server . use ( serveStatic ( path || '.' ) )
69
+ server . use ( serveStatic ( path ) )
59
70
server . listen ( port || 4000 )
60
71
61
72
const msg = '\n'
0 commit comments