Skip to content

Commit

Permalink
fix(#1099): hexo server error when changing the config (#5055)
Browse files Browse the repository at this point in the history
* fix(#1099): hexo server error when changing the config

* fix(#1099): hexo server error when changing the config

Co-authored-by: BuildTools <unconfigured@null.spigotmc.org>
  • Loading branch information
D-Sketon and BuildTools authored Oct 5, 2022
1 parent 4a9314a commit 8aac336
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,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

0 comments on commit 8aac336

Please sign in to comment.