summaryrefslogtreecommitdiffstats
path: root/lib/page/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/page/index.js')
-rw-r--r--lib/page/index.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/page/index.js b/lib/page/index.js
index 8b4fcc9..2dcf704 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -1,6 +1,7 @@
var _ = require('lodash');
var path = require('path');
var direction = require('direction');
+var fm = require('front-matter');
var error = require('../utils/error');
var pathUtil = require('../utils/path');
@@ -25,6 +26,9 @@ function Page(book, filename) {
// Current content
this.content = '';
+ // Short description for the page
+ this.description = '';
+
// Relative path to the page
this.path = filename;
@@ -120,6 +124,7 @@ Page.prototype.getContext = function() {
},
page: {
title: article? article.title : null,
+ description: this.description,
next: next? next.getContext() : null,
previous: prev? prev.getContext() : null,
level: article? article.level : null,
@@ -156,6 +161,17 @@ Page.prototype.toHTML = function(output) {
return this.read()
+ // Parse yaml front matter
+ .then(function() {
+ var parsed = fm(that.content);
+
+ // Extend page with the fontmatter attribute
+ that.description = parsed.attributes.description || '';
+
+ // Keep only the body
+ that.update(parsed.body);
+ })
+
.then(function() {
return hook('page:before');
})
@@ -205,6 +221,12 @@ Page.prototype.toHTML = function(output) {
});
},
+ // Extract description from page's content if no frontmatter
+ onDescription: function(description) {
+ if (that.description) return;
+ that.description = description;
+ },
+
// Convert glossary entries to annotations
annotations: that.book.glossary.annotations()
};