honkit
Version:
HonKit is building beautiful books using Markdown.
31 lines (28 loc) • 1.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const location_1 = __importDefault(require("../../utils/location"));
const fileToOutput_1 = __importDefault(require("./fileToOutput"));
/**
Convert a filePath (absolute) to an url (without hostname).
It returns an absolute path.
"README.md" -> "/"
"test/hello.md" -> "test/hello.html"
"test/README.md" -> "test/"
@param {Output} output
@param {string} filePath
@return {string}
*/
function fileToURL(output, filePath) {
const options = output.getOptions();
const directoryIndex = options.get("directoryIndex");
filePath = (0, fileToOutput_1.default)(output, filePath);
if (directoryIndex && path_1.default.basename(filePath) == "index.html") {
filePath = `${path_1.default.dirname(filePath)}/`;
}
return location_1.default.normalize(filePath);
}
exports.default = fileToURL;