diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-04-14 10:07:51 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-04-14 10:07:51 +0200 |
commit | df46217c78ddb3735005c5514b84269d5614b63e (patch) | |
tree | 300a6514c0c4ff9f382ef285bf8af5d18273db9d /lib | |
parent | d18cc9239614d145b7224260ba5787c149ed46d3 (diff) | |
download | gitbook-df46217c78ddb3735005c5514b84269d5614b63e.zip gitbook-df46217c78ddb3735005c5514b84269d5614b63e.tar.gz gitbook-df46217c78ddb3735005c5514b84269d5614b63e.tar.bz2 |
Improve description extraction and adapt unit tests
Diffstat (limited to 'lib')
-rw-r--r-- | lib/page/html.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/page/html.js b/lib/page/html.js index 5a13dcf..e8d3a85 100644 --- a/lib/page/html.js +++ b/lib/page/html.js @@ -184,12 +184,18 @@ HTMLPipeline.prototype.applyAnnotations = function() { // Extract page description from html // This can totally be improved HTMLPipeline.prototype.extractDescription = function() { - var $p = this.$('p'); + var $ = this.$; + var $p = $('p').first(); + var $next = $p.nextUntil('h1,h2,h3,h4,h5,h6,pre,blockquote,ul,ol,div'); var description = $p.text().trim(); - if (description.length > 300) { - description = description.slice(0, 300).trim()+'...'; - } + + $next.each(function() { + description += ' ' + $(this).text().trim(); + }); + + // Truncate description + description = _.trunc(description, 300); this.opts.onDescription(description); }; |