summaryrefslogtreecommitdiffstats
path: root/lib/api/encodeGlobal.js
blob: b2dd77a38b46fcd064353cf81e806b11367cec75 (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
36
37
38
39
40
41
42
43
44
45
46
var path = require('path');

var fs = require('../utils/fs');

var deprecate = require('./deprecate');
var encodeConfig = require('./encodeConfig');

/**
    Encode a global context into a JS object
    It's the context for page's hook, etc

    @param {Output} output
    @return {Object}
*/
function encodeGlobal(output) {
    var book = output.getBook();
    var logger = output.getLogger();

    var outputFolder = output.getOptions().get('root');

    var result = {
        log: logger,
        config: encodeConfig(output, book.getConfig())
    };

    result.output = {
        name: 'website',

        toURL: function(s) {
            return s;
        },

        writeFile: function(fileName, content) {
            var filePath = path.join(outputFolder, fileName);
            return fs.writeFile(filePath, content);
        }
    };

    result.isLanguageBook = function() {
        return false;
    };

    return result;
}

module.exports = encodeGlobal;