about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config/default.toml3
-rw-r--r--src/index.js5
-rw-r--r--src/views/index.njk6
-rw-r--r--src/views/layouts/main.njk13
-rw-r--r--src/views/post.njk5
-rw-r--r--src/views/term.njk4
-rw-r--r--test/index.test.js1
7 files changed, 36 insertions, 1 deletions
diff --git a/config/default.toml b/config/default.toml
index 9047385..ff1f843 100644
--- a/config/default.toml
+++ b/config/default.toml
@@ -1,6 +1,9 @@
 [server]
 port = 3000
 
+[site]
+title = "Test Site"
+
 [posts]
 folder = "../posts"
 
diff --git a/src/index.js b/src/index.js
index ae277d6..6622a79 100644
--- a/src/index.js
+++ b/src/index.js
@@ -17,7 +17,10 @@ const posts = Posts.getFolder(config.posts.folder)
 
 app.use(
   view(`${__dirname}/views`, {
-    extname: 'njk'
+    extname: 'njk',
+    globals: {
+      site: config.site
+    }
   })
 )
 
diff --git a/src/views/index.njk b/src/views/index.njk
index dcc142c..1bf275e 100644
--- a/src/views/index.njk
+++ b/src/views/index.njk
@@ -1,5 +1,11 @@
+{% extends "layouts/main.njk" %}
+
+{% block body %}
+
 hello world
 
 {% for filename, post in posts %}
   {{ post.data.get('title') }}
 {% endfor %}
+
+{% endblock %}
diff --git a/src/views/layouts/main.njk b/src/views/layouts/main.njk
new file mode 100644
index 0000000..1fe1a93
--- /dev/null
+++ b/src/views/layouts/main.njk
@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8"/>
+    <title>{% block title %}{{ site.title }}{% endblock %}</title>
+  </head>
+  <body>
+    <main>
+      {% block body %}
+      {% endblock %}
+    </main>
+  </body>
+</html>
diff --git a/src/views/post.njk b/src/views/post.njk
index 81f7e3d..d6a4f92 100644
--- a/src/views/post.njk
+++ b/src/views/post.njk
@@ -1,3 +1,8 @@
+{% extends "layouts/main.njk" %}
+
+{% block body %}
+
 {{ post.data.title }}
 
 {{ post.body | safe }}
+{% endblock %}
diff --git a/src/views/term.njk b/src/views/term.njk
index 7ff9871..6ac932e 100644
--- a/src/views/term.njk
+++ b/src/views/term.njk
@@ -1,3 +1,7 @@
+{% extends "layouts/main.njk" %}
+
+{% block body %}
 {% for post in posts %}
   {{ post.data.get('title') }}
 {% endfor %}
+{% endblock %}
diff --git a/test/index.test.js b/test/index.test.js
index 5b5e991..73bbd19 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -11,6 +11,7 @@ test('homepage', t => {
   return request(app.listen())
     .get('/')
     .expect(200)
+    .expect(/<title>Test Site<\/title>/)
     .expect(/hello world/)
     .expect(/This is a test/)
     .then(() => t.pass())