Skip to content

Commit af5e7b4

Browse files
committed
if post.title is empty, set it to post.slug
1 parent a6dc0ea commit af5e7b4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/plugins/processor/post.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ module.exports = ctx => {
117117
data.title = data.link.replace(/^https?:\/\/|\/$/g, '');
118118
}
119119

120+
if (!data.title) {
121+
data.title = data.slug;
122+
}
123+
120124
if (data.permalink) {
121125
data.slug = data.permalink;
122126
delete data.permalink;

test/scripts/processors/post.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,26 @@ describe('post', () => {
615615
}).finally(() => fs.unlink(file.source));
616616
});
617617

618+
619+
it('post - link without title and link', () => {
620+
const body = '';
621+
622+
const file = newFile({
623+
path: 'foo.md',
624+
published: true,
625+
type: 'create',
626+
renderable: true
627+
});
628+
629+
return fs.writeFile(file.source, body).then(() => process(file)).then(() => {
630+
const post = Post.findOne({source: file.path});
631+
632+
post.title.should.eql('foo');
633+
634+
return post.remove();
635+
}).finally(() => fs.unlink(file.source));
636+
});
637+
618638
it('post - category is an alias for categories', () => {
619639
const body = [
620640
'title: "Hello world"',

0 commit comments

Comments
 (0)