mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Expose lookup method for parsable files
This commit is contained in:
+5
-1
@@ -11,5 +11,9 @@ module.exports = {
|
||||
|
||||
// Modifiers
|
||||
SummaryModifier: Modifiers.Summary,
|
||||
ConfigModifier: Modifiers.Config
|
||||
ConfigModifier: Modifiers.Config,
|
||||
|
||||
// Constants
|
||||
CONFIG_FILES: require('./constants/configFiles.js'),
|
||||
IGNORE_FILES: require('./constants/ignoreFiles.js')
|
||||
};
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ FS.prototype.listAllFiles = function(dirName, filterFn) {
|
||||
};
|
||||
|
||||
/**
|
||||
Find a file in a folder (case incensitive)
|
||||
Find a file in a folder (case insensitive)
|
||||
Return the found filename
|
||||
|
||||
@param {String} dirname
|
||||
|
||||
@@ -8,7 +8,7 @@ var parsers = require('../parsers');
|
||||
|
||||
@param {Book} book
|
||||
@param {String} filename
|
||||
@return {Promise<>}
|
||||
@return {Promise<File | Undefined>}
|
||||
*/
|
||||
function findParsableFile(book, filename) {
|
||||
var fs = book.getContentFS();
|
||||
|
||||
+11
-10
@@ -1,13 +1,14 @@
|
||||
|
||||
module.exports = {
|
||||
parseBook: require('./parseBook'),
|
||||
parseSummary: require('./parseSummary'),
|
||||
parseGlossary: require('./parseGlossary'),
|
||||
parseReadme: require('./parseReadme'),
|
||||
parseConfig: require('./parseConfig'),
|
||||
parsePagesList: require('./parsePagesList'),
|
||||
parseIgnore: require('./parseIgnore'),
|
||||
listAssets: require('./listAssets'),
|
||||
parseLanguages: require('./parseLanguages'),
|
||||
parsePage: require('./parsePage')
|
||||
parseBook: require('./parseBook'),
|
||||
parseSummary: require('./parseSummary'),
|
||||
parseGlossary: require('./parseGlossary'),
|
||||
parseReadme: require('./parseReadme'),
|
||||
parseConfig: require('./parseConfig'),
|
||||
parsePagesList: require('./parsePagesList'),
|
||||
parseIgnore: require('./parseIgnore'),
|
||||
listAssets: require('./listAssets'),
|
||||
parseLanguages: require('./parseLanguages'),
|
||||
parsePage: require('./parsePage'),
|
||||
lookupStructureFile: require('./lookupStructureFile')
|
||||
};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
var findParsableFile = require('./findParsableFile');
|
||||
|
||||
/**
|
||||
Lookup a structure file (ex: SUMMARY.md, GLOSSARY.md) in a book. Uses
|
||||
book's config to find it.
|
||||
|
||||
@param {Book} book
|
||||
@param {String} type: one of ["glossary", "readme", "summary", "langs"]
|
||||
@return {Promise<File>} The path of the file found, relative
|
||||
to the book content root.
|
||||
*/
|
||||
function lookupStructureFile(book, type) {
|
||||
var config = book.getConfig();
|
||||
|
||||
var fileToSearch = config.getValue(['structure', type]);
|
||||
|
||||
return findParsableFile(book, fileToSearch);
|
||||
}
|
||||
|
||||
module.exports = lookupStructureFile;
|
||||
+18
-16
@@ -1,6 +1,23 @@
|
||||
var Promise = require('../utils/promise');
|
||||
var IGNORE_FILES = require('../constants/ignoreFiles');
|
||||
|
||||
var DEFAULT_IGNORES = [
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
|
||||
// Ignore files in the templates folder
|
||||
'_layouts'
|
||||
];
|
||||
|
||||
/**
|
||||
Parse ignore files
|
||||
|
||||
@@ -15,22 +32,7 @@ function parseIgnore(book) {
|
||||
var fs = book.getFS();
|
||||
var ignore = book.getIgnore();
|
||||
|
||||
ignore = ignore.add([
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
|
||||
// Ignore files in the templates folder
|
||||
'_layouts'
|
||||
]);
|
||||
ignore = ignore.add(DEFAULT_IGNORES);
|
||||
|
||||
return Promise.serie(IGNORE_FILES, function(filename) {
|
||||
return fs.readAsString(filename)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var findParsableFile = require('./findParsableFile');
|
||||
var Promise = require('../utils/promise');
|
||||
var error = require('../utils/error');
|
||||
var lookupStructureFile = require('./lookupStructureFile');
|
||||
|
||||
/**
|
||||
Parse a ParsableFile using a specific method
|
||||
@@ -55,11 +55,8 @@ function parseFile(fs, file, type) {
|
||||
*/
|
||||
function parseStructureFile(book, type) {
|
||||
var fs = book.getContentFS();
|
||||
var config = book.getConfig();
|
||||
|
||||
var fileToSearch = config.getValue(['structure', type]);
|
||||
|
||||
return findParsableFile(book, fileToSearch)
|
||||
return lookupStructureFile(book, type)
|
||||
.then(function(file) {
|
||||
if (!file) return [undefined, undefined];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user