Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: after enabling "post_asset_folder: true", only one format of posts can be rendered #5531

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/hexo/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export = {
filename_case: 0,
render_drafts: false,
post_asset_folder: false,
post_extensions: [],
relative_link: false,
future: true,
syntax_highlighter: 'highlight.js',
Expand Down
8 changes: 6 additions & 2 deletions lib/plugins/processor/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ export = (ctx: Hexo) => {
// 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 post_asset_folder is set, restrict renderable files to post_extensions or the default file extension
if (result.renderable && ctx.config.post_asset_folder) {
result.renderable = (extname(ctx.config.new_post_name) === extname(path));
if (!Array.isArray(ctx.config.post_extensions) || ctx.config.post_extensions.length === 0) {
result.renderable = (extname(ctx.config.new_post_name) === extname(path));
} else {
result.renderable = ctx.config.post_extensions.includes(extname(path).slice(1));
}
}

return result;
Expand Down
38 changes: 38 additions & 0 deletions test/scripts/processors/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,4 +1359,42 @@ describe('post', () => {
PostAsset.removeById(id)
]);
});

it('post - post_extensions', async () => {
function fooRenderer() {
return '';
}

hexo.extend.renderer.register('md', 'html', fooRenderer, true);
hexo.extend.renderer.register('adoc', 'html', fooRenderer, true);
hexo.extend.renderer.register('ejs', 'html', fooRenderer, true);

hexo.config.post_asset_folder = true;
hexo.config.new_post_name = ':title.md';

hexo.config.post_extensions = null;
pattern.match('_posts/foo.md').should.have.property('renderable', true);
pattern.match('_posts/foo.adoc').should.have.property('renderable', false);
pattern.match('_posts/foo.ejs').should.have.property('renderable', false);

hexo.config.post_extensions = [];
pattern.match('_posts/foo.md').should.have.property('renderable', true);
pattern.match('_posts/foo.adoc').should.have.property('renderable', false);
pattern.match('_posts/foo.ejs').should.have.property('renderable', false);

hexo.config.post_extensions = ['adoc'];
pattern.match('_posts/foo.md').should.have.property('renderable', false);
pattern.match('_posts/foo.adoc').should.have.property('renderable', true);
pattern.match('_posts/foo.ejs').should.have.property('renderable', false);

hexo.config.post_extensions = ['md', 'adoc'];
pattern.match('_posts/foo.md').should.have.property('renderable', true);
pattern.match('_posts/foo.adoc').should.have.property('renderable', true);
pattern.match('_posts/foo.ejs').should.have.property('renderable', false);

hexo.config.post_extensions = ['md', 'adoc', 'ejs'];
pattern.match('_posts/foo.md').should.have.property('renderable', true);
pattern.match('_posts/foo.adoc').should.have.property('renderable', true);
pattern.match('_posts/foo.ejs').should.have.property('renderable', true);
});
});
Loading