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

Migrate to Nunjucks #1214

Closed
1 of 13 tasks
1v9 opened this issue Oct 15, 2019 · 12 comments
Closed
1 of 13 tasks

Migrate to Nunjucks #1214

1v9 opened this issue Oct 15, 2019 · 12 comments

Comments

@1v9
Copy link
Member

1v9 commented Oct 15, 2019

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


Hexo:

  • TypeError: Cannot read property 'replace' of null at Hexo.externalLinkFilter
  • TypeError: Cannot read property 'match' of null at Hexo.hexoMetaGeneratorInject

NexT plugin:


On the road:

when disable external_link, meta_generator

  • all pages show null except archive page, no errors again.
  • layout\archive.swig [Line 29, Column 11] - Unhandled rejection Template render error: unknown block tag: endif
  • layout\archive.swig [Line 40, Column 5] - Unhandled rejection Template render error: unknown block tag: endfor
    Use nunjucks-compatible syntax & operator #1068 (comment)

Pending:

  • layout_partials\head\head.swig - TypeError: Cannot read property 'charAt' of undefined
  • layout_scripts\vendors.swig) - TypeError: Cannot read property 'charAt' of undefined
  • layout_partials\header\menu.swig [Line 8, Column 25] - Unable to call __, which is undefined or falsey
  • layout_macro\post.swig) [Line 223, Column 61] - expected block end in include statement
  • layout\index.swig) [Line 18, Column 28] - Unable to call __, which is undefined or falsey
  • layout_partials\footer.swig) [Line 12, Column 33] - Unable to call Date["now"], which is undefined or falsey
  • layout_third-party\search\index.swig - template not found: localsearch.swig
@theme-next theme-next deleted a comment from issue-label-bot bot Oct 15, 2019
@1v9 1v9 changed the title Nunjucks errors collection Migrate to Nunjucks Oct 15, 2019
@1v9 1v9 added this to the 8.0.0 milestone Oct 15, 2019
@stevenjoezhang
Copy link
Contributor

stevenjoezhang commented Oct 16, 2019

@stevenjoezhang
Copy link
Contributor

PRs:
#1068
#1215

@stevenjoezhang
Copy link
Contributor

stevenjoezhang commented Oct 16, 2019

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

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

@stevenjoezhang
Copy link
Contributor

stevenjoezhang commented Oct 16, 2019

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

Medium
In JavaScript land the pace of development moves very fast and there are literally hundreds of competing libraries to accomplish almost…

@AlynxZhou
Copy link

AlynxZhou commented Oct 17, 2019

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.

@AlynxZhou
Copy link

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
Copy link

AlynxZhou commented Oct 17, 2019

@stevenjoezhang @ivan-nginx @1v9 About #1068 (comment), 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

{%- set current_year %}
(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.

@stevenjoezhang
Copy link
Contributor

@AlynxZhou Thanks so much!

@AlynxZhou
Copy link

@AlynxZhou Thanks so much!

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

@AlynxZhou
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

Jobs done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants