Skip to content

Commit

Permalink
if post.title is empty, set it to post.slug (#3672)
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertqin authored and yoshinorin committed Aug 30, 2019
1 parent 5f05653 commit f57f700
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
Expand Down

0 comments on commit f57f700

Please sign in to comment.