summaryrefslogtreecommitdiffstats
path: root/lib/output/generatePage.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/generatePage.js')
-rw-r--r--lib/output/generatePage.js76
1 files changed, 40 insertions, 36 deletions
diff --git a/lib/output/generatePage.js b/lib/output/generatePage.js
index 30a798a..a93d4b0 100644
--- a/lib/output/generatePage.js
+++ b/lib/output/generatePage.js
@@ -1,5 +1,6 @@
var Promise = require('../utils/promise');
var error = require('../utils/error');
+var timing = require('../utils/timing');
var Parse = require('../parse');
var Templating = require('../templating');
@@ -18,50 +19,53 @@ function generatePage(output, page) {
var book = output.getBook();
var engine = createTemplateEngine(output);
- return Parse.parsePage(book, page)
- .then(function(resultPage) {
- var file = resultPage.getFile();
- var filePath = file.getPath();
- var parser = file.getParser();
- var context = JSONUtils.encodeBookWithPage(book, resultPage);
+ return timing.measure(
+ 'page.generate',
+ Parse.parsePage(book, page)
+ .then(function(resultPage) {
+ var file = resultPage.getFile();
+ var filePath = file.getPath();
+ var parser = file.getParser();
+ var context = JSONUtils.encodeBookWithPage(book, resultPage);
- if (!parser) {
- return Promise.reject(error.FileNotParsableError({
- filename: filePath
- }));
- }
+ if (!parser) {
+ return Promise.reject(error.FileNotParsableError({
+ filename: filePath
+ }));
+ }
- // Call hook "page:before"
- return callPageHook('page:before', output, resultPage)
+ // Call hook "page:before"
+ return callPageHook('page:before', output, resultPage)
- // Escape code blocks with raw tags
- .then(function(currentPage) {
- return parser.page.prepare(currentPage.getContent());
- })
+ // Escape code blocks with raw tags
+ .then(function(currentPage) {
+ return parser.page.prepare(currentPage.getContent());
+ })
- // Render templating syntax
- .then(function(content) {
- return Templating.render(engine, filePath, content, context);
- })
+ // Render templating syntax
+ .then(function(content) {
+ return Templating.render(engine, filePath, content, context);
+ })
- // Render page using parser (markdown -> HTML)
- .then(parser.page).get('content')
+ // Render page using parser (markdown -> HTML)
+ .then(parser.page).get('content')
- // Post processing for templating syntax
- .then(function(content) {
- return Templating.postRender(engine, content);
- })
+ // Post processing for templating syntax
+ .then(function(content) {
+ return Templating.postRender(engine, content);
+ })
- // Return new page
- .then(function(content) {
- return resultPage.set('content', content);
- })
+ // Return new page
+ .then(function(content) {
+ return resultPage.set('content', content);
+ })
- // Call final hook
- .then(function(currentPage) {
- return callPageHook('page', output, currentPage);
- });
- });
+ // Call final hook
+ .then(function(currentPage) {
+ return callPageHook('page', output, currentPage);
+ });
+ })
+ );
}
module.exports = generatePage;