theme-next / hexo-theme-next

Elegant and powerful theme for Hexo.
https://theme-next.org
Other
8.17k stars 2.05k forks source link

Migrate to Nunjucks #1214

Closed 1v9 closed 5 years ago

1v9 commented 5 years ago

Any developer could log issues here, see njk, should use Hexo v4/master version.


Hexo:


Pending:

stevenjoezhang commented 5 years ago

References: https://github.com/AlynxZhou/hexo-renderer-nunjucks/issues/1 https://github.com/mozilla/nunjucks/issues/307 https://github.com/mozilla/nunjucks/issues/569 https://github.com/mozilla/nunjucks/issues/1116 https://github.com/mozilla/nunjucks/pull/1209

stevenjoezhang commented 5 years ago

PRs: https://github.com/theme-next/hexo-theme-next/pull/1068 https://github.com/theme-next/hexo-theme-next/pull/1215

stevenjoezhang commented 5 years ago

Benchmark (Need more test cases) https://github.com/stevenjoezhang/nunjucks-vs-swig

GitHub
stevenjoezhang/nunjucks-vs-swig
Contribute to stevenjoezhang/nunjucks-vs-swig development by creating an account on GitHub.
stevenjoezhang commented 5 years ago

https://medium.com/engineers-optimizely/js-templating-transitioning-from-swig-to-nunjucks-ac0e94d1794b

Medium
JS Templating: Transitioning from swig to nunjucks
In JavaScript land the pace of development moves very fast and there are literally hundreds of competing libraries to accomplish almost…
AlynxZhou commented 5 years ago

Ah, although I use neither Hexo nor NexT now, I can still help about things of nunjucks plugin, though I have not upload my plugin a lot time, I think it's still the newest alive nunjucks plugin.

By the way, it's name on https://npmjs.com is called hexo-renderer-njucks because hexo-renderer-nunjucks hexo-renderer-njks hexo-renderer-njk are all dead.

npm | build amazing things
AlynxZhou commented 5 years ago

About Unable to call Date["now"], which is undefined or falsey: Nunjucks does not work like ejs or swig, which treat expressions as JavaScript expressions, you need to register JavaScript function them and then you can use them, so try to passing them via Hexo, I am not familiar to how to do this with Hexo, but it should work.

AlynxZhou commented 5 years ago

@stevenjoezhang @ivan-nginx @1v9 About https://github.com/theme-next/hexo-theme-next/pull/1068#issuecomment-518756742, although I never use import, I find something related to this problem (from https://mozilla.github.io/nunjucks/templating.html#set):

It is also possible to capture the contents of a block into a variable using block assignments. The syntax is similar to the standard set, except that the = is omitted, and everything until the {% endset %} is captured.

So nunjucks says endfor is unknown may because you set current_year without a initial value, and nunjucks treats it as a block assign, you may change https://github.com/theme-next/hexo-theme-next/blob/290fc6c497b843b36dada50500720b5f825a15d2/layout/_macro/post-collapse.swig#L4 (and other places like this) into:

{% set current_year = '1970' %}

and test again, I don't have a valid _config.yml for NexT, so I cannot test it now.

Nunjucks
stevenjoezhang commented 5 years ago

@AlynxZhou Thanks so much!

AlynxZhou commented 5 years ago

@AlynxZhou Thanks so much!

Nothing, if you never find my repo and reference my issue, I would never see this.

AlynxZhou commented 5 years ago

Looks like layout_macro\post.swig) [Line 223, Column 61] - expected block end in include statement and layout\archive.swig [Line 29, Column 11] - Unhandled rejection Template render error: unknown block tag: endif are also the same reason, so go for a test and see whether is has been solved.

stevenjoezhang commented 5 years ago

Thanks, I'll check for that. Moreover, your theme - hexo-theme-aria, is pretty nice. I have already referenced some code from it, otherwise I might waste a whole day figuring out why page.posts in for tag doesn't work with out toArray() 😂

stevenjoezhang commented 5 years ago

Jobs done