summaryrefslogtreecommitdiffstats
path: root/lib/output/helper/resolveFileToURL.js
blob: 3f52713180c6b46641c925397f74a3e48887e18e (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
var LocationUtils = require('../../utils/location');

var fileToURL = require('./fileToURL');

/**
 * Resolve an absolute path (extracted from a link)
 *
 * @param {Output} output
 * @param {String} filePath
 * @return {String}
 */
function resolveFileToURL(output, filePath) {
    // Convert /test.png -> test.png
    filePath = LocationUtils.toAbsolute(filePath, '', '');

    var page = output.getPage(filePath);

    // if file is a page, return correct .html url
    if (page) {
        filePath = fileToURL(output, filePath);
    }

    return LocationUtils.normalize(filePath);
}

module.exports = resolveFileToURL;