mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 03:16:40 +00:00
Improve book.findFile to be case incensitive
This commit is contained in:
+5
-4
@@ -614,12 +614,13 @@ Book.prototype.findFile = function(filename) {
|
||||
|
||||
var filepath = basename+ext;
|
||||
|
||||
return that.fileExists(filepath)
|
||||
.then(function(exists) {
|
||||
if (!exists) return null;
|
||||
return fs.findFile(that.root, filepath)
|
||||
.then(function(realFilepath) {
|
||||
if (!realFilepath) return null;
|
||||
|
||||
return {
|
||||
parser: parsers.get(ext),
|
||||
path: filepath
|
||||
path: realFilepath
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,6 +30,7 @@ var fsUtils = {
|
||||
fs.exists(path, d.resolve);
|
||||
return d.promise;
|
||||
},
|
||||
findFile: findFile,
|
||||
existsSync: fs.existsSync.bind(fs),
|
||||
readFileSync: fs.readFileSync.bind(fs),
|
||||
clean: cleanFolder,
|
||||
@@ -178,4 +179,15 @@ function cleanFolder(root) {
|
||||
});
|
||||
}
|
||||
|
||||
// Find a file in a folder (case incensitive)
|
||||
// Return the real filename
|
||||
function findFile(root, filename) {
|
||||
return Q.nfcall(fs.readdir, root)
|
||||
.then(function(files) {
|
||||
return _.find(files, function(file) {
|
||||
return (file.toLowerCase() == filename.toLowerCase());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = fsUtils;
|
||||
|
||||
Reference in New Issue
Block a user