Skip to content

Commit

Permalink
fix(post): skip before_post_render and after_post_render on non-posts (
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Dec 10, 2022
1 parent c02aefe commit 0fe24a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,27 @@ class Post {
return Promise.reject(new Error('No input file or string!')).asCallback(callback);
}

// Files like js and css are also processed by this function, but they do not require preprocessing like markdown
// data.source does not exist when tag plugins call the markdown renderer
const isPost = !data.source || ['html', 'htm'].includes(ctx.render.getOutput(data.source));

if (!isPost) {
return promise.then(content => {
data.content = content;
ctx.log.debug('Rendering file: %s', magenta(source));

return ctx.render.render({
text: data.content,
path: source,
engine: data.engine,
toString: true
});
}).then(content => {
data.content = content;
return data;
}).asCallback(callback);
}

// disable Nunjucks when the renderer specify that.
let disableNunjucks = ext && ctx.render.renderer.get(ext) && !!ctx.render.renderer.get(ext).disableNunjucks;

Expand Down
10 changes: 10 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ describe('Post', () => {
await unlink(path);
});

it('render() - skip js', async () => {
const content = 'let a = "{{ 1 + 1 }}"';

const data = await post.render(null, {
content,
source: 'render_test.js'
});
data.content.trim().should.eql(content);
});

it('render() - toString', async () => {
const content = 'foo: 1';

Expand Down

0 comments on commit 0fe24a4

Please sign in to comment.