summaryrefslogtreecommitdiffstats
path: root/lib/output/website/onFinish.js
blob: 526745805408ce5dc736f7f24abb005e9b441038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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(tplOut) {
        return writeFile(output, filePath, tplOut.getContent());
    });
}

module.exports = onFinish;