@@ -25,14 +25,12 @@ function getDevServer(compilation) {
25
25
// console.debug('URL', ctx.request.url);
26
26
27
27
// TODO filter out node modules, only page / user requests from brower
28
- if ( ctx . request . url . endsWith ( '/' ) ) {
28
+ // TODO make sure this only happens for "pages", nor partials or fixtures, templates, et)
29
+ if ( ctx . request . url . endsWith ( '/' ) || ctx . request . url . endsWith ( '.html' ) ) {
29
30
// console.log('URL ends with /');
30
31
// TODO get port from compilation
31
- ctx . redirect ( `http://localhost:1984${ ctx . request . url } index.html` ) ;
32
- }
33
-
34
- // make sure this only happens for "pages", nor partials or fixtures, templates, et)
35
- if ( ctx . request . url . indexOf ( '.html' ) >= 0 ) {
32
+ // ctx.redirect(`http://localhost:1984${ctx.request.url}index.html`);
33
+ // }
36
34
let title = config . title ;
37
35
38
36
const metaOutletContent = config . meta . map ( item => {
@@ -48,11 +46,14 @@ function getDevServer(compilation) {
48
46
} ) . join ( '\n' ) ;
49
47
50
48
// TODO get pages path from compilation
51
- const barePath = `${ userWorkspace } /pages${ ctx . request . url . replace ( '.html' , '' ) } ` ;
49
+ const barePath = ctx . request . url . endsWith ( '/' )
50
+ ? `${ userWorkspace } /pages${ ctx . request . url } index`
51
+ : `${ userWorkspace } /pages${ ctx . request . url . replace ( '.html' , '' ) } ` ;
52
+
52
53
// console.debug('bare path', barePath);
53
54
54
55
let contents = `
55
- <!DOCTYPE html>
56
+ <!DOCTYPE html>
56
57
<html lang="en" prefix="og:http://ogp.me/ns#">
57
58
<head>
58
59
<title>${ title } </title>
@@ -68,14 +69,21 @@ function getDevServer(compilation) {
68
69
</html>
69
70
` ;
70
71
72
+
71
73
if ( fs . existsSync ( `${ barePath } .html` ) ) {
72
74
// console.debug('this route exists as HTML');
73
75
contents = await fsp . readFile ( `${ barePath } .html` , 'utf-8' ) ;
74
- } else if ( fs . existsSync ( `${ barePath } .md` ) || fs . existsSync ( `${ userWorkspace } /pages${ ctx . request . url . replace ( '/index.html' , '.md' ) } ` ) ) {
76
+ } else if ( fs . existsSync ( `${ barePath } .md` )
77
+ || fs . existsSync ( `${ userWorkspace } /pages${ ctx . request . url . replace ( '/index.html' , '.md' ) } ` )
78
+ || fs . existsSync ( `${ barePath . replace ( '/index' , '.md' ) } ` ) ) {
79
+
75
80
// TODO all this lookup could probably be handled a bit more gracefully perhaps?
81
+ // console.debug('this route exists as markdown');
76
82
const markdownPath = fs . existsSync ( `${ barePath } .md` )
77
83
? `${ barePath } .md`
78
- : `${ userWorkspace } /pages${ ctx . request . url . replace ( '/index.html' , '.md' ) } ` ;
84
+ : fs . existsSync ( `${ barePath . replace ( '/index' , '.md' ) } ` )
85
+ ? `${ barePath . replace ( '/index' , '.md' ) } `
86
+ : `${ userWorkspace } /pages${ ctx . request . url . replace ( '/index.html' , '.md' ) } ` ;
79
87
const markdownContents = await fsp . readFile ( markdownPath , 'utf-8' ) ;
80
88
81
89
// console.debug('this route exists as a markdown file', markdownPath);
0 commit comments