Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ function parseFilename(config, path) {
const data = permalink.parse(path);

if (data) {
return data;
if (data.title !== undefined) {
return data;
}
return Object.assign(data, {
title: slugize(path)
});
}

return {
Expand Down
28 changes: 28 additions & 0 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,34 @@ describe('post', () => {
]);
});

it('post - parse unusual file name', async () => {
const body = [
'title: "Hello world"',
'---'
].join('\n');

const file = newFile({
path: '20060102.html',
published: true,
type: 'create',
renderable: true
});

hexo.config.new_post_name = ':year:month:day';

await writeFile(file.source, body);
await process(file);
const post = Post.findOne({ source: file.path });

post.slug.should.eql('20060102');
post.date.format('YYYY-MM-DD').should.eql('2006-01-02');

return Promise.all([
post.remove(),
unlink(file.source)
]);
});

it('post - extra data in file name', async () => {
const body = [
'title: "Hello world"',
Expand Down