From f57f700fd768f1f400352ddf58a90d16bcf87a25 Mon Sep 17 00:00:00 2001 From: Rupert Date: Fri, 30 Aug 2019 16:10:03 +0800 Subject: [PATCH] if post.title is empty, set it to post.slug (#3672) --- lib/plugins/processor/post.js | 4 ++++ test/scripts/processors/post.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index 56da936086..6518e504b6 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -117,6 +117,10 @@ module.exports = ctx => { data.title = data.link.replace(/^https?:\/\/|\/$/g, ''); } + if (!data.title) { + data.title = data.slug; + } + if (data.permalink) { data.slug = data.permalink; delete data.permalink; diff --git a/test/scripts/processors/post.js b/test/scripts/processors/post.js index 00f8ad2818..3fa2eb09ff 100644 --- a/test/scripts/processors/post.js +++ b/test/scripts/processors/post.js @@ -615,6 +615,26 @@ describe('post', () => { }).finally(() => fs.unlink(file.source)); }); + + it('post - link without title and link', () => { + const body = ''; + + const file = newFile({ + path: 'foo.md', + published: true, + type: 'create', + renderable: true + }); + + return fs.writeFile(file.source, body).then(() => process(file)).then(() => { + const post = Post.findOne({source: file.path}); + + post.title.should.eql('foo'); + + return post.remove(); + }).finally(() => fs.unlink(file.source)); + }); + it('post - category is an alias for categories', () => { const body = [ 'title: "Hello world"',