summaryrefslogtreecommitdiffstats
path: root/lib/output/ebook/getCoverPath.js
blob: c2192d48640da7277fe07ea571baa7873318b05b (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
var path = require('path');
var fs = require('../../utils/fs');

/**
    Resolve path to cover file to use

    @param {Output}
    @return {String}
*/
function getCoverPath(output) {
    var outputRoot = output.getRoot();
    var book = output.getBook();
    var config = book.getConfig();
    var cover = config.getValue('cover', 'cover.jpg');

    // Resolve to absolute
    cover = fs.pickFile(outputRoot, cover);
    if (cover) {
        return cover;
    }

    // Multilingual? try parent folder
    if (book.isLanguageBook()) {
        cover = fs.pickFile(path.join(outputRoot, '..'), cover);
    }

    return cover;
}

module.exports = getCoverPath;