diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-25 15:43:55 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-25 15:43:55 +0100 |
commit | 327e90e8ec731352d659aa0ada810332fcd66a18 (patch) | |
tree | 2acdb2e1f7c42d91ff098b5cabfa4e57701756bc /lib/page/html.js | |
parent | 9253b764fad8452fb1cf0760be482b692fdfb728 (diff) | |
download | gitbook-327e90e8ec731352d659aa0ada810332fcd66a18.zip gitbook-327e90e8ec731352d659aa0ada810332fcd66a18.tar.gz gitbook-327e90e8ec731352d659aa0ada810332fcd66a18.tar.bz2 |
Extract description from page's front matter
Fixes #1079 and #795
Diffstat (limited to 'lib/page/html.js')
-rw-r--r-- | lib/page/html.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/page/html.js b/lib/page/html.js index bd9ec91..bce6cd2 100644 --- a/lib/page/html.js +++ b/lib/page/html.js @@ -14,6 +14,9 @@ function HTMLPipeline(htmlString, opts) { _.bindAll(this); this.opts = _.defaults(opts || {}, { + // Called once the description has been found + onDescription: function(description) { }, + // Calcul new href for a relative link onRelativeLink: _.identity, @@ -178,11 +181,21 @@ HTMLPipeline.prototype.applyAnnotations = function() { }); }; +// Extract page description from html +// This can totally be improved +HTMLPipeline.prototype.extractDescription = function() { + var $p = this.$('p').first(); + var description = $p.text().trim().slice(0, 155); + + this.opts.onDescription(description); +}; + // Write content to the pipeline HTMLPipeline.prototype.output = function() { var that = this; return Promise() + .then(this.extractDescription) .then(this.transformImages) .then(this.transformHeadings) .then(this.transformCodeBlocks) |