1
- const liveServer = require ( 'live-server' )
2
- const isSSR = ! ! process . env . SSR
3
- const middleware = [ ]
1
+ const liveServer = require ( 'live-server' ) ;
2
+ const isSSR = ! ! process . env . SSR ;
3
+ const middleware = [ ] ;
4
4
5
5
if ( isSSR ) {
6
- const Renderer = require ( './packages/docsify-server-renderer/build.js' )
6
+ const { initJSDOM } = require ( './test/_helper' ) ;
7
+
8
+ const dom = initJSDOM ( '' , {
9
+ url : 'https://127.0.0.1:3000' ,
10
+ } ) ;
11
+
12
+ require = require ( 'esm' ) ( module /* , options */ ) ;
13
+
14
+ const {
15
+ Renderer,
16
+ getServerHTMLTemplate,
17
+ } = require ( './packages/docsify-server-renderer/index' ) ;
18
+
19
+ debugger ;
20
+
7
21
const renderer = new Renderer ( {
8
- template : `
9
- <!DOCTYPE html>
10
- <html lang="en">
11
- <head>
12
- <meta charset="UTF-8">
13
- <title>docsify</title>
14
- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
15
- <link rel="stylesheet" href="/themes/vue.css" title="vue">
16
- </head>
17
- <body>
18
- <!--inject-app-->
19
- <!--inject-config-->
20
- <script src="/lib/docsify.js"></script>
21
- </body>
22
- </html>` ,
22
+ template : getServerHTMLTemplate ( ) ,
23
23
config : {
24
24
name : 'docsify' ,
25
25
repo : 'docsifyjs/docsify' ,
@@ -32,24 +32,23 @@ if (isSSR) {
32
32
'/de-de/changelog' : '/changelog' ,
33
33
'/zh-cn/changelog' : '/changelog' ,
34
34
'/changelog' :
35
- 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG'
36
- }
35
+ 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG' ,
36
+ } ,
37
37
} ,
38
- path : './'
39
- } )
38
+ } ) ;
40
39
41
40
middleware . push ( function ( req , res , next ) {
42
41
if ( / \. ( c s s | j s ) $ / . test ( req . url ) ) {
43
- return next ( )
42
+ return next ( ) ;
44
43
}
45
- renderer . renderToString ( req . url ) . then ( html => res . end ( html ) )
46
- } )
44
+ renderer . renderToString ( req . url ) . then ( html => res . end ( html ) ) ;
45
+ } ) ;
47
46
}
48
47
49
48
const params = {
50
49
port : 3000 ,
51
50
watch : [ 'lib' , 'docs' , 'themes' ] ,
52
- middleware
53
- }
51
+ middleware,
52
+ } ;
54
53
55
- liveServer . start ( params )
54
+ liveServer . start ( params ) ;
0 commit comments