diff options
Diffstat (limited to 'lib/output/website/onFinish.js')
-rw-r--r-- | lib/output/website/onFinish.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/output/website/onFinish.js b/lib/output/website/onFinish.js new file mode 100644 index 0000000..e3560e2 --- /dev/null +++ b/lib/output/website/onFinish.js @@ -0,0 +1,35 @@ +var Promise = require('../../utils/promise'); +var JSONUtils = require('../../json'); +var Templating = require('../../templating'); +var writeFile = require('../helper/writeFile'); +var createTemplateEngine = require('./createTemplateEngine'); + +/** + Finish the generation, write the languages index + + @param {Output} + @return {Output} +*/ +function onFinish(output) { + var book = output.getBook(); + var options = output.getOptions(); + var prefix = options.get('prefix'); + + if (!book.isMultilingual()) { + return Promise(output); + } + + var filePath = 'index.html'; + var engine = createTemplateEngine(output, filePath); + var context = JSONUtils.encodeOutput(output); + + // Render the theme + return Templating.renderFile(engine, prefix + '/languages.html', context) + + // Write it to the disk + .then(function(html) { + return writeFile(output, filePath, html); + }); +} + +module.exports = onFinish; |