From 63668ca89f055b2233a8aa6caf4213853918d68d Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 15 Nov 2020 21:43:36 -0600 Subject: Switch to handlebars for templating --- src/templates.js | 115 +++++++++++++++---------------------------------------- 1 file changed, 31 insertions(+), 84 deletions(-) (limited to 'src/templates.js') diff --git a/src/templates.js b/src/templates.js index b748853..293f0e4 100644 --- a/src/templates.js +++ b/src/templates.js @@ -1,86 +1,33 @@ -module.exports = { - titlebar: ``, - footer: ``, +const fs = require('fs'); +const path = require('path'); +const handlebars = require("handlebars"); + +function loadTemplate(templates, name, filepath){ + const templateContent = fs.readFileSync(filepath).toString() + templates[name] = handlebars.compile(templateContent); +} + +function loadPartial(name, filepath){ + handlebars.registerPartial(name, fs.readFileSync(filepath).toString()); +} + +function setUpTemplates(){ + loadPartial("navigation", path.join(__dirname, "templates/navigation.html")) + loadPartial("footer", path.join(__dirname, "templates/footer.html")) + loadPartial("feed", path.join(__dirname, "templates/feed.html")) - index: { - pre: ` - - - - Mark's Kitchen - - - - - - - - -

Welcome to Mark's Kitchen

`, - post: ` - ` - }, - bread: { - pre: ` - - - - Mark's Kitchen - Bread - - - - - - - -

- < - Bread -

- Some highlights (and lowlights) of breadmaking`, - post: ` - ` - }, - blog: { - pre: ` - - - - Mark's Kitchen - Blog - - - - - - - -

- < - Blog -

`, - post: ` - ` - } + let templates = {}; + loadTemplate(templates, "index", path.join(__dirname, 'templates/index.html')) + loadTemplate(templates, "bread", path.join(__dirname, 'templates/bread.html')) + loadTemplate(templates, "blog", path.join(__dirname, 'templates/blog.html')) + loadTemplate(templates, "blog-single", path.join(__dirname, 'templates/blog-single.html')) + loadTemplate(templates, "tags", path.join(__dirname, 'templates/tags.html')) + loadTemplate(templates, "misc", path.join(__dirname, 'templates/misc.html')) + loadTemplate(templates, "projects", path.join(__dirname, 'templates/projects.html')) + return templates +} + + +module.exports = { + setUpTemplates } \ No newline at end of file -- cgit v1.2.3