diff options
Diffstat (limited to 'lib/output/website/onPage.js')
-rw-r--r-- | lib/output/website/onPage.js | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/output/website/onPage.js b/lib/output/website/onPage.js index a5598e4..8af3622 100644 --- a/lib/output/website/onPage.js +++ b/lib/output/website/onPage.js @@ -1,5 +1,9 @@ +var path = require('path'); +var omit = require('omit-keys'); + var Templating = require('../../templating'); var JSONUtils = require('../../json'); +var LocationUtils = require('../../utils/location'); var Modifiers = require('../modifiers'); var writeFile = require('../helper/writeFile'); var getModifiers = require('../getModifiers'); @@ -16,22 +20,39 @@ function onPage(output, page) { var options = output.getOptions(); var file = page.getFile(); var prefix = options.get('prefix'); + var book = output.getBook(); + var config = book.getConfig(); + var engine = createTemplateEngine(output, page.getPath()); + // Output file path + var filePath = fileToOutput(output, file.getPath()); + + // Calcul relative path to the root + var outputDirName = path.dirname(filePath); + var basePath = LocationUtils.normalize(path.relative(outputDirName, './')); + return Modifiers.modifyHTML(page, getModifiers(output, page)) .then(function(resultPage) { // Generate the context var context = JSONUtils.encodeBookWithPage(output.getBook(), resultPage); + context.config = config.getValues().toJS(); context.template = { getJSContext: function() { - return {}; + return { + page: omit(context.page, 'content'), + config: context.config, + file: context.file, + gitbook: context.gitbook, + basePath: basePath, + book: { + language: null //context.book.language + } + }; } }; - // Output file path - var filePath = fileToOutput(output, file.getPath()); - // Render the theme return Templating.renderFile(engine, prefix + '/page.html', context) |