blog.rust-lang.org icon indicating copy to clipboard operation
blog.rust-lang.org copied to clipboard

Replace Handlebars with Tera

Open avrong opened this issue 3 years ago • 14 comments

Closes #599

I replaced the handlebars crate with tera, adapted the Generator, and its render_template method, converted the month_name filter and the templates.

I'm not sure that all I've done is correct, so happy to make it better. The thing I'm not confident about is should the string concatenation be preferred in HTML args inside the templates:

// injecting
<link href="https://blog.rust-lang.org/{{ blog.prefix }}feed.xml">

// concatenation
<link href="{{ "https://blog.rust-lang.org/" ~ blog.prefix ~ "feed.xml" }}">

avrong avatar Sep 10 '20 18:09 avrong

Thank you for your PR! I’ll test this over the weekend, but it looks good to me. I think the former style you used in the PR is fine for now.

XAMPPRocky avatar Sep 10 '20 20:09 XAMPPRocky

Given that we're holding off on Zolaification, is there a strong reason to switch to Tera? If it simplifies things I'm all for it though.

Manishearth avatar Sep 12 '20 01:09 Manishearth

cc @pietroalbini

Manishearth avatar Sep 12 '20 01:09 Manishearth

Personally I prefer Tera templates because of their explicitness in template tags. Maybe it would also make them easier to understand for the new people and those who had experience with Jinja2/Django templates :)

avrong avatar Sep 12 '20 02:09 avrong

@Manishearth Yes, I think we want Tera for templating, it's much more powerful in ways that we care about. (For example; you can easily generate HTML from remote urls such as team data), and more DRY (you can set variables in the template, functions are just rust functions).

I also personally prefer the syntax, I find things like blocks are harder to get wrong in tera than handlebars' sigil heavy syntax. I know docs.rs switched to using it awhile ago.

None of this is in the current PR of course, it's a pretty straight 1-to-1 port.

XAMPPRocky avatar Sep 12 '20 10:09 XAMPPRocky

Seems okay to me, then.

Manishearth avatar Sep 12 '20 18:09 Manishearth

Oh, this is on the blog repo, I didn't realize :)

Manishearth avatar Sep 12 '20 18:09 Manishearth

Regardless of Zola, I also vastly prefer working with Tera compared to Handlebars.

pietroalbini avatar Sep 14 '20 09:09 pietroalbini

I really prefer how handlebars is more broadly known than terra, but at the same time, I don't do a ton of work in this codebase, so I don't think that should be a blocker.

steveklabnik avatar Sep 14 '20 13:09 steveklabnik

FWIW Tera's syntax is derived from templating languages like Jinja (Django/Python) and Twig (Symphony/PHP), which are incredibly popular in their respective languages. So I think whether one is more broad than the other really depends on your previous web experience and what you were already using before.

XAMPPRocky avatar Sep 15 '20 09:09 XAMPPRocky

Any updates on this? @XAMPPRocky

avrong avatar Nov 10 '20 19:11 avrong

@avrong Sorry for the delay, and I can't actually merge this anymore, so someone else will have to approve it.

XAMPPRocky avatar Nov 11 '20 07:11 XAMPPRocky

@avrong sorry we let this slide for so long. Do you have any interest in picking this back up?

rylev avatar Jun 22 '22 11:06 rylev

@rylev oh, yeah, will find a time to update this soon

avrong avatar Jun 22 '22 12:06 avrong