hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.55k stars 4.86k forks source link

Inconsistent check for Nunjucks disabling flag #3860

Closed FlyingDR closed 4 years ago

FlyingDR commented 5 years ago

Nunjucks disabling flag check is potentially broken because of inconsistency of logic of passing and checking disableNunjucks parameter from renderers.

As of v4.0.0 disableNunjucks flag is defined by checking corresponding flag from renderer that is received through get() method. This get() method selects between normal and sync stores, but uses normal store by default. However, as can be seen from renderer registration method, this normal store contains Promise and hence provides no access to disableNunjucks flag that can be passed from renderer. Such flag will be stored into storeSync which contains original renderer function.

Correct code for disableNunjucks flag checking should use storeSync:

const disableNunjucks = ext && ctx.render.renderer.get(ext) && !!ctx.render.renderer.get(ext, true).disableNunjucks;

notice second true argument for get().

curbengh commented 4 years ago

PR welcome

noraj commented 4 years ago

By chance could it help with https://github.com/hexojs/hexo/issues/3259 ?

curbengh commented 4 years ago

By chance could it help with #3259 ?

disableNunjucks is used in renderer to disable nunjucks for all the files covered by the renderer.

hexo.extend.renderer.register('md', 'html', (data, { disableNunjucks: true }) => {
  // ...
});

For example this plugin https://github.com/think-in-universe/hexo-stop-tag-plugins disables all nunjucks in markdown files. A side effect is that tag plugin {% is also not processed, which is not optimal. User should be able to write {{ in a post regardless it's wrapped in a codeblock or not, without worrying it gets rendered as nunjucks; while at the same time, able to use tag plugin.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

noraj commented 4 years ago

unstale

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.