Skip to content

Commit

Permalink
Merge d819f18 into f2ddc99
Browse files Browse the repository at this point in the history
  • Loading branch information
ppoffice committed Jul 4, 2019
2 parents f2ddc99 + d819f18 commit 8e2fc8c
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
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
Expand Up @@ -119,4 +119,35 @@ describe('Excerpt', () => {
'baz'
].join('\n'));
});

it('skip processing if post/page.excerpt is present', () => {
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 8e2fc8c

Please sign in to comment.