Parse a page, read its content and parse the YAMl header

@param {Book} book
@param {Page} page
@return {Promise<Page>}
552278
function parsePage(book, page) {
    var fs = book.getContentFS();
    var file = page.getFile();

    return fs.readAsString(file.getPath())
    .then(function(content) {
        return parsePageFromString(page, content);
    });
}
204184
function parseFilePage(book, filePath) {
    var fs = book.getContentFS();

    return fs.statFile(filePath)
    .then(
        function(file) {
            var page = Page.createForFile(file);
            return parsePage(book, page);
        },
        function(err) {
            // file doesn't exist
            return null;
        }
    )
    .fail(function(err) {
        var logger = book.getLogger();
        logger.error.ln('error while parsing page "' + filePath + '":');
        throw err;
    });
}
446146
function parse(method, req, res, options) {
    return new Promise(function(resolve, reject) {
        BodyParser[method](options)(req, res, function(err) {
            if (err) {
                return reject(err);
            }

            return resolve();
        });
    });
}
562830
function parseConfig(book) {
    var fs = book.getFS();
    var config = book.getConfig();

    return Promise.some(CONFIG_FILES, function(filename) {
        // Is this file ignored?
        if (book.isFileIgnored(filename)) {
            return;
        }

        // Try loading it
        return fs.loadAsObject(filename)
        .then(function(cfg) {
            return fs.statFile(filename)
            .then(function(file) {
                return {
                    file: file,
                    values: cfg
                };
            });
        })
        .fail(function(err) {
            if (err.code != 'MODULE_NOT_FOUND') throw(err);
            else return Promise(false);
        });
    })

    .then(function(result) {
        var values = result? result.values : {};
        values = validateConfig(values);

        // Set the file
        if (result.file) {
            config = config.setFile(result.file);
        }

        // Merge with old values
        config = config.mergeValues(values);

        return book.setConfig(config);
    });
}
324061
function (request, callback) {
  const parsed = url.parse(request.url)
  if (!parsed.hostname || !parsed.path) return callback()

  const manifest = manifestMap[parsed.hostname]
  if (!manifest) return callback()

  const page = backgroundPages[parsed.hostname]
  if (page && parsed.path === `/${page.name}`) {
    // Disabled due to false positive in StandardJS
    // eslint-disable-next-line standard/no-callback-literal
    return callback({
      mimeType: 'text/html',
      data: page.html
    })
  }

  fs.readFile(path.join(manifest.srcDirectory, parsed.path), function (err, content) {
    if (err) {
      // Disabled due to false positive in StandardJS
      // eslint-disable-next-line standard/no-callback-literal
      return callback(-6) // FILE_NOT_FOUND
    } else {
      return callback(content)
    }
  })
}
40288
function(file, type) {
    var promise = new Parse.Promise();

    if (typeof(FileReader) === "undefined") {
      return Parse.Promise.error(new Parse.Error(
          Parse.Error.FILE_READ_ERROR,
          "Attempted to use a FileReader on an unsupported browser."));
    }

    var reader = new FileReader();
    reader.onloadend = function() {
      if (reader.readyState !== 2) {
        promise.reject(new Parse.Error(
            Parse.Error.FILE_READ_ERROR,
            "Error reading file."));
        return;
      }

      var dataURL = reader.result;
      var matches = /^data:([^;]*);base64,(.*)$/.exec(dataURL);
      if (!matches) {
        promise.reject(new Parse.Error(
            Parse.ERROR.FILE_READ_ERROR,
            "Unable to interpret data URL: " + dataURL));
        return;
      }

      promise.resolve(matches[2], type || matches[1]);
    };
    reader.readAsDataURL(file);
    return promise;
  }
1280655
function Router_parseRequest(method, parsedUrl, headers) {
        var all = [];

        this.routes.forEach(function (routeRule) {
            all.push(
                new Promise(function (resolve, reject) {
                    try {
                        resolve(routeRule.parseRequest(method, parsedUrl, headers));
                    } catch (e) {
                        reject(e);
                    }
                })
            );
        });
        return Promise.all(all).then(function (data) {
            var route;
            while (data.length) {
                route = data.shift();
                if (Type.isArray(route) && route.length === 2) {
                    return route;
                }
            }
            return [];
        });
    }
920864
def do_get_page(parser, token):
    
    bits = token.split_contents()
    if 4 != len(bits):
        raise TemplateSyntaxError('%r expects 4 arguments' % bits[0])
    if bits[-2] != 'as':
        raise TemplateSyntaxError(
            '%r expects "as" as the second argument' % bits[0])
    page_filter = parser.compile_filter(bits[1])
    varname = bits[-1]
    return GetPageNode(page_filter, varname)
1281967
function Router_process(method, parsedUrl, headers) {

        return this.parseRequest(method, parsedUrl, headers)
            .then(function (routeRule) {
                if (Type.isArray(routeRule) && routeRule.length === 2) {
                    return Promise.resolve(routeRule);
                }
                // only on not found throw an error 404
                throw new error.HttpError(404, core.toObject(routeRule), 'Not found');
            }, function (e) {
                throw new error.HttpError(500, {}, 'Not found', e);
            });
    }
1171933
function Pages(pages) {
  this.pages = [];
  if (typeof pages === 'undefined') return;
  if (!Array.isArray(pages)) {
    throw new TypeError('expected pages to be an Array');
  }
  this.addPages(pages);
}
734485
function(page) {

            var $ = cheerio.load(page.content);

            // Replace top level li.chapter with li.part
            $('ul.summary > li.chapter').each(function(i, elem) {
                var li = $(elem);

                // Replace the classes if the chapter is actually a part, and add a divider
                if (li.text().indexOf('-XPARTX-') > 0) {
                    li.removeClass('chapter');
                    li.addClass('part');

                    // Don't add a divider before the first part, let it come straight after the Introduction page
                    if (i > 1)
                        li.before('<li class="part divider" />');
                }
            });

            // remove chapter numbers from any intro pages (and child pages)
            $('ul.summary > li.chapter span > b').remove();
            $('ul.summary > li.chapter a > b').remove();

            // Remove the chapter number from the part header
            $('ul.summary > li.part > span > b').remove();
            $('ul.summary > li.part > a > b').remove();

            // Replace the nasty munging of the name for part heading
            $('ul.summary > li.part > span').each(function(i, elem) {
                var span = $(elem);
                span.text(span.text().replace(/-XPARTX-/, ""));
            });

            // Bump the remaining chapter numbers so each chapter is only unique
            // within the part
            $('ul.summary > li.part li.chapter b').each(function(i, elem) {
                var b = $(elem);
                var text = b.text();
                var index = text.indexOf('.');
                if (index > -1)
                    b.text(text.substring(index + 1));
            });

            page.content = $.html();
            return page;
        }
126852
function parsePageFromString(page, content) {
    // Parse page YAML
    var parsed = fm(content);

    return page.merge({
        content:    parsed.body,
        attributes: Immutable.fromJS(parsed.attributes),
        dir:        direction(parsed.body)
    });
}
1178021
function modifyHTML(page, operations) {
    var html = page.getContent();
    var $ = cheerio.load(html);

    return Promise.forEach(operations, function(op) {
        return op($);
    })
    .then(function() {
        var resultHTML = $.html();
        return page.set('content', resultHTML);
    });
}
287217
function(body) {
    var $     = cheerio.load(body),
        page  = {};

    // Meta signals
    page.title = $('title').text() || null;
    page.description = $('meta[name=description]').attr('content') || null;
    page.author = $('meta[name=author]').attr('content') || null;
    page.keywords = $('meta[name=keywords]').attr('content') || null;

    // Heading signals
    var h1s = 0;
    $('h1').each(function() {
      h1s++;
    });
    page.heading1 = $('body h1:first-child').text().trim().replace('\n', '');
    page.totalHeadings = h1s;

    // Accessibility signals
    var totalImgs       = 0,
        accessibleImgs  = 0;
    $('img').each(function(index) {
      totalImgs++;
      if ($(this).attr('alt') || $(this).attr('title')) {
        accessibleImgs++;
      }
    });
    page.imgAccessibility = (accessibleImgs / totalImgs) * 100;
    return page;
  }
941242
function parseStructureFile(book, type) {
    var fs = book.getContentFS();

    return lookupStructureFile(book, type)
    .then(function(file) {
        if (!file) return [undefined, undefined];

        return parseFile(fs, file, type);
    });
}
370737
function reanderPage(Handler, data) {
    React.render(React.createElement(Handler, { data: data }), document);
}
1020304
function initBook(rootFolder) {
    var extension = '.md';

    return fs.mkdirp(rootFolder)

    // Parse the summary and readme
    .then(function() {
        var fs = createNodeFS(rootFolder);
        var book = Book.createForFS(fs);

        return Parse.parseReadme(book)

        // Setup default readme if doesn't found one
        .fail(function() {
            var readmeFile = File.createWithFilepath('README' + extension);
            var readme = Readme.create(readmeFile);
            return book.setReadme(readme);
        });
    })
    .then(Parse.parseSummary)

    .then(function(book) {
        var logger = book.getLogger();
        var summary = book.getSummary();
        var summaryFile = summary.getFile();
        var summaryFilename = summaryFile.getPath() || ('SUMMARY' + extension);

        var articles = summary.getArticlesAsList();

        // Write pages
        return Promise.forEach(articles, function(article) {
            var articlePath = article.getPath();
            var filePath = articlePath? path.join(rootFolder, articlePath) : null;
            if (!filePath) {
                return;
            }

            return fs.assertFile(filePath, function() {
                return fs.ensureFile(filePath)
                .then(function() {
                    logger.info.ln('create', article.getPath());
                    return fs.writeFile(filePath, '# ' + article.getTitle() + '\n\n');
                });
            });
        })

        // Write summary
        .then(function() {
            var filePath = path.join(rootFolder, summaryFilename);

            return fs.ensureFile(filePath)
            .then(function() {
                logger.info.ln('create ' + path.basename(filePath));
                return fs.writeFile(filePath, summary.toText(extension));
            });
        })

        // Log end
        .then(function() {
            logger.info.ln('initialization is finished');
        });
    });
}