Skip to content

Commit

Permalink
Merge 64fa502 into 47650c3
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Nov 29, 2022
2 parents 47650c3 + 64fa502 commit 11e8c4d
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
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
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 11e8c4d

Please sign in to comment.