diff --git a/core/frontend/meta/description.js b/core/frontend/meta/description.js index 82cbdd9fe9..b684dafcdf 100644 --- a/core/frontend/meta/description.js +++ b/core/frontend/meta/description.js @@ -1,6 +1,6 @@ const _ = require('lodash'); const settingsCache = require('../../shared/settings-cache'); -const getExcerpt = require('./generate-excerpt'); +const generateExcerpt = require('./generate-excerpt'); function getDescription(data, root, options = {}) { const context = root ? root.context : null; @@ -47,7 +47,7 @@ function getDescription(data, root, options = {}) { description = data.post[`${options.property}_description`] || data.post.custom_excerpt || data.post.meta_description - || getExcerpt(data.post.html || '', {words: 50}) + || generateExcerpt(data.post.html || '', {words: 50}) || settingsCache.get('description') || ''; } else { @@ -59,7 +59,7 @@ function getDescription(data, root, options = {}) { description = data.post[`${options.property}_description`] || data.post.custom_excerpt || data.post.meta_description - || getExcerpt(data.post.html || '', {words: 50}) + || generateExcerpt(data.post.html || '', {words: 50}) || settingsCache.get('description') || ''; } else { @@ -70,7 +70,7 @@ function getDescription(data, root, options = {}) { description = data.page[`${options.property}_description`] || data.page.custom_excerpt || data.page.meta_description - || getExcerpt(data.page.html || '', {words: 50}) + || generateExcerpt(data.page.html || '', {words: 50}) || settingsCache.get('description') || ''; } else { diff --git a/core/frontend/meta/generate-excerpt.js b/core/frontend/meta/generate-excerpt.js index 32fef0a916..df3f040eed 100644 --- a/core/frontend/meta/generate-excerpt.js +++ b/core/frontend/meta/generate-excerpt.js @@ -1,6 +1,6 @@ const downsize = require('downsize'); -function getExcerpt(html, truncateOptions) { +function generateExcerpt(html, truncateOptions) { truncateOptions = truncateOptions || {}; // Strip inline and bottom footnotes let excerpt = html.replace(/.*?<\/a>/gi, ''); @@ -20,4 +20,4 @@ function getExcerpt(html, truncateOptions) { return downsize(excerpt, truncateOptions); } -module.exports = getExcerpt; +module.exports = generateExcerpt; diff --git a/test/unit/meta/generate-excerpt_spec.js b/test/unit/meta/generate-excerpt_spec.js index f1f26be21e..2655ebbb62 100644 --- a/test/unit/meta/generate-excerpt_spec.js +++ b/test/unit/meta/generate-excerpt_spec.js @@ -1,7 +1,7 @@ const should = require('should'); -const getExcerpt = require('../../../core/frontend/meta/generate-excerpt'); +const generateExcerpt = require('../../../core/frontend/meta/generate-excerpt'); -describe('getExcerpt', function () { +describe('generateExcerpt', function () { it('should return html excerpt with no html', function () { const html = '

There are
10
types
of people in the world:' + 'c those who ' + @@ -11,7 +11,7 @@ describe('getExcerpt', function () { const expected = 'There are 10 types of people in the world: those who understand trinary, those who ' + 'don\'t and those>> who mistake it <for> binary.'; - getExcerpt(html, {}).should.equal(expected); + generateExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt strips multiple inline footnotes', function () { @@ -22,7 +22,7 @@ describe('getExcerpt', function () { const expected = 'Testing, my footnotes. And stuff. Footnotewith a link right after.'; - getExcerpt(html, {}).should.equal(expected); + generateExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt striping inline and bottom footnotes', function () { @@ -34,14 +34,14 @@ describe('getExcerpt', function () { const expected = 'Testing a very short post with a single footnote.'; - getExcerpt(html, {}).should.equal(expected); + generateExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt truncated by word', function () { const html = '

Hello World! It\'s me!

'; const expected = 'Hello World!'; - getExcerpt(html, {words: '2'}).should.equal(expected); + generateExcerpt(html, {words: '2'}).should.equal(expected); }); it('should return html excerpt truncated by words with non-ascii characters', @@ -49,7 +49,7 @@ describe('getExcerpt', function () { const html = '

Едквюэ опортэат праэчынт ючю но, квуй эю

'; const expected = 'Едквюэ опортэат'; - getExcerpt(html, {words: '2'}).should.equal(expected); + generateExcerpt(html, {words: '2'}).should.equal(expected); }); it('should return html excerpt truncated by character', @@ -57,7 +57,7 @@ describe('getExcerpt', function () { const html = '

Hello World! It\'s me!

'; const expected = 'Hello Wo'; - getExcerpt(html, {characters: '8'}).should.equal(expected); + generateExcerpt(html, {characters: '8'}).should.equal(expected); }); it('should fall back to 50 words if not specified', @@ -70,7 +70,7 @@ describe('getExcerpt', function () { const expected = 'There are 10 types of people in the world: those who understand trinary, those who ' + 'don\'t and those>> who mistake it <for> binary.'; - getExcerpt(html).should.equal(expected); + generateExcerpt(html).should.equal(expected); }); it('should truncate plain text for custom excerpts', @@ -85,6 +85,6 @@ describe('getExcerpt', function () { 'your story and make a nice summary for your readers. It\s only allowed to truncate anything ' + 'after 300 characters. This give'; - getExcerpt(html, {characters: '300'}).should.equal(expected); + generateExcerpt(html, {characters: '300'}).should.equal(expected); }); });