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

Replace default swig engine with nunjucks #2903

Open
wants to merge 9 commits into
base: master
from

Conversation

10 participants
@oncletom
Copy link
Contributor

oncletom commented Dec 11, 2017

(this is an in-progress PR)

It feels reasonable to remove swig due to its deprecation and various issues reporting it: #2895, #1593, #1625, #1915, #2295

This PR aims to:

  • remove all calls to swig and swig-extras
  • choice 1, replacing swig with nunjucks as a native renderer (and then processing .njk files)
  • or choice 2, delegating the rendering to an external renderer (hexo-renderer-swig to opt-in for legacy themes, hexo-renderer-j2 or hexo-render-nunjucks or hexo-renderer-nunjucks2 etc. to opt-in for nunjucks)
  • ensure default theme iissnan/hexo-theme-next is compatible with the outcome of this PR

What do you think?

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 11, 2017

Coverage Status

Coverage decreased (-0.2%) to 96.983% when pulling dbabd3b on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

@kovtunos

This comment has been minimized.

Copy link

kovtunos commented Dec 12, 2017

Replace swig with nunjucks v3.

@oncletom

This comment has been minimized.

Copy link
Contributor Author

oncletom commented Dec 12, 2017

Thanks @kovtunos.

Shall we still process .swig files with nunjucks? By default I would not do it but project wise, I don't know if it is relevant.

oncletom added some commits Dec 13, 2017

Add nunjucks renderer
Temporarily render swig templates with nunjucks
@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 13, 2017

Coverage Status

Coverage decreased (-0.4%) to 96.794% when pulling d994d52 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

@oncletom

This comment has been minimized.

Copy link
Contributor Author

oncletom commented Dec 13, 2017

At the moment all swig tests seem to pass with nunjucks as a renderer. Except one which is related to the for override (override "for" tag in test/scripts/renderers/swig.js).

The test is ran against this data structure:

var data = {
      arr: {
        toArray() {
          return [1, 2, 3];
        }
      }
    };

Is that something we want to keep? Is that related to a Collection object (like posts) which has a toArray() method to move out of the Warehouse realm?

I would find it less hacky to write {% for post in posts | list %} for example. I would understand we would like to keep a maximum compatibility

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 13, 2017

Coverage Status

Coverage decreased (-0.06%) to 97.17% when pulling 1e85e39 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

@NoahDragon NoahDragon added this to the 4.0 milestone Dec 16, 2017

@NoahDragon

This comment has been minimized.

Copy link
Member

NoahDragon commented Dec 16, 2017

Hi @oncletom , my two cents, we should keep the backward capability. The most popular Hexo theme NexT (https://github.com/iissnan/hexo-theme-next) is still using the swig. However, if the change could work on NexT, then we could merge this change for Hexo 4.

@NoahDragon NoahDragon referenced this pull request Dec 16, 2017

Open

Hexo 4.0 Roadmap #2492

11 of 43 tasks complete

oncletom added some commits Dec 17, 2017

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 17, 2017

Coverage Status

Coverage decreased (-0.03%) to 97.201% when pulling 1478019 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

1 similar comment
@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 17, 2017

Coverage Status

Coverage decreased (-0.03%) to 97.201% when pulling 1478019 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

oncletom added some commits Dec 17, 2017

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 17, 2017

Coverage Status

Coverage increased (+0.005%) to 97.231% when pulling 7179a08 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 17, 2017

Coverage Status

Coverage increased (+0.0007%) to 97.227% when pulling d97c6f7 on oncletom:feature/remove-swig into c8d47b8 on hexojs:master.

@huiwang

This comment has been minimized.

Copy link

huiwang commented Jan 5, 2018

hi, this is an exciting proposal. it will make it possible to use async helper in themes.

@charsi

This comment has been minimized.

Copy link

charsi commented Jan 13, 2018

The next theme is now hosted here -- https://github.com/theme-next/hexo-theme-next/

@NoahDragon

This comment has been minimized.

Copy link
Member

NoahDragon commented Mar 15, 2018

@oncletom, is this still working in progress?

@oncletom

This comment has been minimized.

Copy link
Contributor Author

oncletom commented Mar 15, 2018

Hi @NoahDragon!

I would say most of the work is done. At the moment nunjucks is configured to handle .swig files but that can be changed/removed/put under a deprecation notice setting.

Next step would be to try it out with hexo-theme-next to make sure it works, either out of the box or with additional fixes.

I don't know if anybody has time to do it, or to test and to report the issues in this thread.

Otherwise let me know if there are any useful pointers to integrate this contribution to the 4.x branch sooner or later 🙂

@NoahDragon

This comment has been minimized.

Copy link
Member

NoahDragon commented Mar 15, 2018

@oncletom Thanks for the update. I will test this change when I have a chance. 😄

@djmtype

This comment has been minimized.

Copy link

djmtype commented Jun 27, 2018

What's the status on using Nunjucks? I'm only pointing this out because the official site no longer mentions it along side of pug, ejs, haml and swig. https://hexo.io/docs/themes.html#layout Besides, it seems *.ejs is currently the adopted template language of Hexo.

@chenbojian

This comment has been minimized.

Copy link

chenbojian commented Dec 5, 2018

it looks like nunjunks is merged to node itself. And it cause some errors to install hexo on node 11.3.0. #3380

@tomap

This comment has been minimized.

Copy link
Contributor

tomap commented Dec 5, 2018

@chenbojian it's unrelated to this issue

@oncletom

This comment has been minimized.

Copy link
Contributor Author

oncletom commented Dec 5, 2018

Well, I don't know—I can put more efforts into it.

I can also make it a separate plugin if needed and if none already exist to do the job.

Any feedback from the @hexojs team?

@YoshinoriN

This comment has been minimized.

Copy link
Member

YoshinoriN commented Dec 16, 2018

I can also make it a separate plugin

IMHO, should merge this change and bump up to hexo version to V4. No need separate to plugin.

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