diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-03-02 11:11:39 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-03-02 11:11:39 +0100 |
commit | 21d696423068082adb79b85917719ea18562e4d2 (patch) | |
tree | 88c8db7120c91d1909441763a20663de3ce8f1ff /lib/page | |
parent | 4499ccc501950f472ade2175e742d707752ef39d (diff) | |
download | gitbook-21d696423068082adb79b85917719ea18562e4d2.zip gitbook-21d696423068082adb79b85917719ea18562e4d2.tar.gz gitbook-21d696423068082adb79b85917719ea18562e4d2.tar.bz2 |
Extend "page" with frontmatter attributes
Diffstat (limited to 'lib/page')
-rw-r--r-- | lib/page/index.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/page/index.js b/lib/page/index.js index f3a8f39..6c63489 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -23,12 +23,13 @@ function Page(book, filename) { this.book = book; this.log = this.book.log; + // Map of attributes from YAML frontmatter + // Description is also extracted by default from content + this.attributes = {}; + // Current content this.content = ''; - // Short description for the page - this.description = ''; - // Relative path to the page this.path = location.normalize(filename); @@ -122,16 +123,15 @@ Page.prototype.getContext = function() { mtime: this.mtime, type: this.type }, - page: { + page: _.extend({}, this.attributes, { title: article? article.title : null, - description: this.description, next: next? next.getContext() : null, previous: prev? prev.getContext() : null, level: article? article.level : null, depth: article? article.depth : 0, content: this.content, dir: dir - } + }) }, gitbook.getContext(), this.book.getContext(), @@ -165,8 +165,8 @@ Page.prototype.toHTML = function(output) { .then(function() { var parsed = fm(that.content); - // Extend page with the fontmatter attribute - that.description = parsed.attributes.description || ''; + // Extract attributes + that.attributes = parsed.attributes; // Keep only the body that.update(parsed.body); @@ -223,8 +223,8 @@ Page.prototype.toHTML = function(output) { // Extract description from page's content if no frontmatter onDescription: function(description) { - if (that.description) return; - that.description = description; + if (that.attributes.description) return; + that.attributes.description = description; }, // Convert glossary entries to annotations |