Skip to content

Commit

Permalink
Merge pull request #3612 from ppoffice/master
Browse files Browse the repository at this point in the history
feat(filter): use existing excerpt if possible
  • Loading branch information
yoshinorin authored Jul 27, 2019
2 parents 14157c5 + c321663 commit 4931608
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/plugins/filter/after_post_render/excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const rExcerpt = /<!--+\s*more\s*--+>/i;
function excerptFilter(data) {
const { content } = data;

if (rExcerpt.test(content)) {
if (typeof data.excerpt !== 'undefined') {
data.more = content;
} else if (rExcerpt.test(content)) {
data.content = content.replace(rExcerpt, (match, index) => {
data.excerpt = content.substring(0, index).trim();
data.more = content.substring(index + match.length).trim();
Expand Down
31 changes: 31 additions & 0 deletions test/scripts/filters/excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,35 @@ describe('Excerpt', () => {
'baz'
].join('\n'));
});

it('skip processing if post/page.excerpt is present in the front-matter', () => {
const content = [
'foo',
'<!-- more -->',
'bar'
].join('\n');

const data = {
content,
excerpt: 'baz'
};

excerpt(data);

data.content.should.eql([
'foo',
'<!-- more -->',
'bar'
].join('\n'));

data.excerpt.should.eql([
'baz'
].join('\n'));

data.more.should.eql([
'foo',
'<!-- more -->',
'bar'
].join('\n'));
});
});

0 comments on commit 4931608

Please sign in to comment.