getnikola / nikola-themes

Themes for Nikola
https://themes.getnikola.com/
70 stars 51 forks source link

material-theme: Simplify post's available translations retrieving. #196

Closed vincent-ferotin closed 3 years ago

vincent-ferotin commented 3 years ago

Instead of previous loop, iterating over all translated languages and displaying each lang. after some tests, we now proceed in 2 steps:

  1. computing available languages first, before iterating, and filter them at this step;
  2. iterating over previous result, and displaying links to translated posts.

This allows use of all loop variables provided by Jinja2, notably loop.first and loop.last, with now correct values (previous loop, as filtering list elements inside its body, forbid usage of them). Moreover, this better allows modifying (e.g. by a child/sub-theme) HTML tags structure for displaying the list of translated posts links. Last, this change use more Jinja "expected way-to-do" and less programming idioms, and should potentially be more "designers friendly".

Kwpolska commented 3 years ago
  1. The template will not compile. Please test changes before making pull requests.
  2. This snippet was copied from base-jinja. If we were to make this change, it should be made there first.
  3. This change cannot be made to base-jinja, because base-jinja is auto-generated from base, and our conversion script would need to special-case this (and remove the endif at the end somehow).
  4. This “Jinja2 idiom” requires the reader to think more than the current for-if structure, which is immediately obvious to a reader.

This PR is rejected. You can make this change in your own theme if you need it.