From 9caa9c39e59aba47de1646081591ed4c826abfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 17 Feb 2016 17:34:27 +0100 Subject: [PATCH] Use _layouts folders as base for templates --- lib/output/website.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/output/website.js b/lib/output/website.js index 1ec0548ea..a208802cc 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -12,6 +12,11 @@ function themeID(plugin) { return 'theme-' + plugin; } +// Directory for a theme with the templates +function templatesPath(dir) { + return path.join(dir, '_layouts'); +} + function WebsiteOutput() { Output.apply(this, arguments); @@ -50,15 +55,16 @@ WebsiteOutput.prototype.prepare = function() { var searchPaths = _.chain([ // The book itself can contains a "_layouts" folder - that.book.root, + '_layouts', // Installed plugin (it can be identical to themeDefault.root) - that.theme.root, + '_layouts', // Is default theme still installed that.themeDefault? that.themeDefault.root : null ]) .compact() + .map(templatesPath) .uniq() .value(); @@ -87,8 +93,13 @@ WebsiteOutput.prototype.prepare = function() { WebsiteOutput.prototype.onPage = function(page) { var that = this; + // Parse the page + return page.toHTML(this) + // Render the page template with the same context as the json output - return this.render('page', this.getPageContext(page)) + .then(function() { + return that.render('page', that.getPageContext(page)); + }) // Write the HTML file .then(function(html) { @@ -109,7 +120,7 @@ WebsiteOutput.prototype.render = function(tpl, context) { // Return a complete name for a template WebsiteOutput.prototype.templateName = function(name) { - return path.join('_layouts', this.name, name+'.html'); + return path.join(this.name, name+'.html'); }; module.exports = conrefsLoader(WebsiteOutput);