34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
"use strict";
|
|
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 promise_1 = __importDefault(require("../utils/promise"));
|
|
const parsers_1 = __importDefault(require("../parsers"));
|
|
/**
|
|
Find a file parsable (Markdown or AsciiDoc) in a book
|
|
|
|
@param {Book} book
|
|
@param {string} filename
|
|
@return {Promise<File | Undefined>}
|
|
*/
|
|
function findParsableFile(book, filename) {
|
|
const fs = book.getContentFS();
|
|
const ext = path_1.default.extname(filename);
|
|
const basename = path_1.default.basename(filename, ext);
|
|
const basedir = path_1.default.dirname(filename);
|
|
// Ordered list of extensions to test
|
|
const exts = parsers_1.default.extensions;
|
|
return promise_1.default.some(exts, (ext) => {
|
|
const filepath = basename + ext;
|
|
return fs.findFile(basedir, filepath).then((found) => {
|
|
if (!found || book.isContentFileIgnored(found)) {
|
|
return undefined;
|
|
}
|
|
return fs.statFile(found);
|
|
});
|
|
});
|
|
}
|
|
exports.default = findParsableFile;
|