diff --git a/lib/plugins/tag/post_link.ts b/lib/plugins/tag/post_link.ts index 4460cef8fe..782714a1d2 100644 --- a/lib/plugins/tag/post_link.ts +++ b/lib/plugins/tag/post_link.ts @@ -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); diff --git a/test/scripts/tags/post_link.js b/test/scripts/tags/post_link.js index d476933d0a..999f2cad48 100644 --- a/test/scripts/tags/post_link.js +++ b/test/scripts/tags/post_link.js @@ -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', () => { @@ -36,6 +41,10 @@ describe('post_link', () => { postLink(['foo', 'test']).should.eql('test'); }); + it('no title', () => { + postLink(['no-title']).should.eql('no-title'); + }); + it('should escape tag in title by default', () => { postLink(['title-with-tag']).should.eql('"Hello" <new world>!'); });