Skip to content

Commit

Permalink
Merge b8b9d4a into 064daa4
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 18, 2020
2 parents 064daa4 + b8b9d4a commit 92cb773
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/plugins/tag/post_link.js
Expand Up @@ -13,8 +13,9 @@ module.exports = ctx => {
const Post = ctx.model('Post');

return function postLinkTag(args) {
const error = `<a href="#">Post not found: ${args.join(' ') || 'Invalid post_link'}</a>`;
const slug = args.shift();
if (!slug) return;
if (!slug) return error;

let escape = args[args.length - 1];
if (escape === 'true' || escape === 'false') {
Expand All @@ -24,7 +25,7 @@ module.exports = ctx => {
}

const post = Post.findOne({slug});
if (!post) return;
if (!post) return error;

let title = args.length ? args.join(' ') : post.title;
const attrTitle = escapeHTML(title);
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/tags/post_link.js
Expand Up @@ -58,10 +58,10 @@ describe('post_link', () => {
});

it('no slug', () => {
should.not.exist(postLink([]));
postLink([]).should.eql('<a href="#">Post not found: Invalid post_link</a>');
});

it('post not found', () => {
should.not.exist(postLink(['bar']));
postLink(['bar']).should.eql('<a href="#">Post not found: bar</a>');
});
});

0 comments on commit 92cb773

Please sign in to comment.