Skip to content

Commit

Permalink
feat(tags/post_link): use slug when title is empty (#5220)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 2, 2023
1 parent f791362 commit 5837bb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/tag/post_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export = ctx => {
throw new Error(`Post not found: post_link ${slug}.`);
}

let title = args.length ? args.join(' ') : post.title;
let title = args.length ? args.join(' ') : post.title || post.slug;
// Let attribute be the true post title so it appears in tooltip.
const attrTitle = escapeHTML(post.title);
const attrTitle = escapeHTML(post.title || post.slug);
if (escape === 'true') title = escapeHTML(title);

const link = encodeURL(new URL(post.path, ctx.config.url).pathname);
Expand Down
9 changes: 9 additions & 0 deletions test/scripts/tags/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('post_link', () => {
source: 'fôo',
slug: 'fôo',
title: 'Hello world'
},
{
source: 'no-title',
slug: 'no-title',
title: ''
}])));

it('default', () => {
Expand All @@ -36,6 +41,10 @@ describe('post_link', () => {
postLink(['foo', 'test']).should.eql('<a href="/foo/" title="Hello world">test</a>');
});

it('no title', () => {
postLink(['no-title']).should.eql('<a href="/no-title/" title="no-title">no-title</a>');
});

it('should escape tag in title by default', () => {
postLink(['title-with-tag']).should.eql('<a href="/title-with-tag/" title="&quot;Hello&quot; &lt;new world&gt;!">&quot;Hello&quot; &lt;new world&gt;!</a>');
});
Expand Down

0 comments on commit 5837bb8

Please sign in to comment.