0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed missing renames getExcerpt -> generateExcerpt

refs: fbf0636936

- I renamed this pattern in a bunch of places, but missed a few, leaving the code messy and confusing
- This makes the naming consistent
This commit is contained in:
Hannah Wolfe 2021-07-02 09:35:07 +01:00
parent 4ac89c0176
commit 84c2154cbe
No known key found for this signature in database
GPG key ID: 9F8C7532D0A6BA55
3 changed files with 16 additions and 16 deletions

View file

@ -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 {

View file

@ -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 href="#fn.*?rel="footnote">.*?<\/a>/gi, '');
@ -20,4 +20,4 @@ function getExcerpt(html, truncateOptions) {
return downsize(excerpt, truncateOptions);
}
module.exports = getExcerpt;
module.exports = generateExcerpt;

View file

@ -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 = '<p>There are <br />10<br> types<br/> of people in <img src="a">the world:' +
'<img src=b alt="c"> those who <img src="@" onclick="javascript:alert(\'hello\');">' +
@ -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 &lt;for&gt; 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 = '<p>Hello <strong>World! It\'s me!</strong></p>';
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 = '<p>Едквюэ опортэат <strong>праэчынт ючю но, квуй эю</strong></p>';
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 = '<p>Hello <strong>World! It\'s me!</strong></p>';
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 &lt;for&gt; 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);
});
});