From 8aac33692f80bcf0a9d1c733c55bcd96c24b722a Mon Sep 17 00:00:00 2001 From: D_Sketon <2055272094@qq.com> Date: Wed, 5 Oct 2022 23:38:56 +0800 Subject: [PATCH] fix(#1099): hexo server error when changing the config (#5055) * fix(#1099): hexo server error when changing the config * fix(#1099): hexo server error when changing the config Co-authored-by: BuildTools --- lib/plugins/processor/post.js | 7 ++++++- test/scripts/processors/post.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index 02ced04d17..4e61712800 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -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 { diff --git a/test/scripts/processors/post.js b/test/scripts/processors/post.js index f9e2dea156..5132f4670e 100644 --- a/test/scripts/processors/post.js +++ b/test/scripts/processors/post.js @@ -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"',