Skip to content

Commit

Permalink
Merge pull request #4781 from kristofzerbe/master
Browse files Browse the repository at this point in the history
fix(#1490): if `post_asset_folder` is set, restrict renderable files to default file extension
  • Loading branch information
yoshinorin authored Jan 1, 2022
2 parents c749815 + 8f01a02 commit 8465a61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ module.exports = ctx => {

if (!result || isHiddenFile(result.path)) return;

// checks only if there is a renderer for the file type or if is included in skip_render
result.renderable = ctx.render.isRenderable(path) && !isMatch(path, ctx.config.skip_render);

// if post_asset_folder is set, restrict renderable files to default file extension
if (result.renderable && ctx.config.post_asset_folder) {
result.renderable = (extname(ctx.config.new_post_name) === extname(path));
}

return result;
}),

Expand Down
12 changes: 12 additions & 0 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ describe('post', () => {
hexo.config.skip_render = ['_posts/foo/**'];
pattern.match('_posts/foo/bar.html').should.have.property('renderable', false);
hexo.config.skip_render = [];

// Skip render in the subdir assets if post_asset_folder is enabled
hexo.config.post_asset_folder = true;
pattern.match('_posts/foo/subdir/bar.html').should.have.property('renderable', false);
pattern.match('_posts/foo/subdir/bar.css').should.have.property('renderable', false);
pattern.match('_posts/foo/subdir/bar.js').should.have.property('renderable', false);
hexo.config.post_asset_folder = false;

// Render in the subdir assets if post_asset_folder is disabled
pattern.match('_posts/foo/subdir/bar.html').should.have.property('renderable', true);
pattern.match('_posts/foo/subdir/bar.css').should.have.property('renderable', true);
pattern.match('_posts/foo/subdir/bar.js').should.have.property('renderable', true);
});

it('asset - post_asset_folder disabled', async () => {
Expand Down

0 comments on commit 8465a61

Please sign in to comment.