Change serve_jst() so the template is responsible for calling env.site.serve()
authorNick Downing <downing.nick@gmail.com>
Mon, 22 Oct 2018 00:41:42 +0000 (11:41 +1100)
committerNick Downing <downing.nick@gmail.com>
Mon, 22 Oct 2018 01:42:46 +0000 (12:42 +1100)
.gitignore
Site.js
site/index.html.jst

index 77978dd..574daf9 100644 (file)
@@ -1,3 +1,5 @@
+.*.js
 /jst_server-*.tgz
 /node_modules
 /yarn.lock
+/yarn-error.log
diff --git a/Site.js b/Site.js
index c09c7ba..daa0857 100644 (file)
--- a/Site.js
+++ b/Site.js
@@ -98,9 +98,7 @@ Site.prototype.serve_jst = async function(env, pathname) {
       throw err
     return false
   }
-  let out = []
-  await jst(env, out)
-  this.serve(env, Buffer.from(out.join('')), 'jst')
+  await jst(env)
   return true
 }
 
@@ -155,6 +153,7 @@ Site.prototype.serve_zip = async function(env, pathname) {
 Site.prototype.respond = async function(env) {
   while (true) {
     if (env.pathname_pos >= env.pathname.length) {
+      // directory without trailing slash
       this.redirect(env, env.pathname + '/index.html')
       return
     }
@@ -168,6 +167,7 @@ Site.prototype.respond = async function(env) {
 
     if (filename.length === 0) {
       if (j >= env.pathname.length)
+        // directory with trailing slash
         this.redirect(env, env.pathname + 'index.html')
       else
         this.die(env, `empty directory name in ${env.pathname}`)
index d1f46e6..072e682 100644 (file)
@@ -1,10 +1,16 @@
-return async (_env, _out) => {
-  html {
-    head {
-      link(rel="stylesheet" type="text/css" href="css/styles.css") {}
-    }
-    body {
-      p {'Hello, world'}
-    }
-  }
+return async env => {
+  env.site.serve(
+    env,
+    Buffer.from(
+      html {
+        head {
+          link(rel="stylesheet" type="text/css" href="css/styles.css") {}
+        }
+        body {
+          p {'Hello, world'}
+        }
+      }
+    ),
+    'index.jst'
+  )
 }