section macro works with taxonomies + config extra.section_fullarticles

This commit is contained in:
southerntofu 2021-02-10 19:50:06 +01:00
parent 98e7dd1e23
commit c4f8be6c8a
5 changed files with 53 additions and 9 deletions

View File

@ -89,6 +89,10 @@ Example: use `home_section = "blog"` to feature the blog/ section on the homepag
`home_fullarticles = false` decides whether to show article contents on the homepage. When disabled, articles will have their summary displayed, or simply their title/date when they don't have a summary. This option only applies to sites using a `home_section`.
### section_fullarticles
`section_fullarticles = false` decides whether to show articles contents in a section. When disabled, articles will have their summary displayed, or simply their title/date when they don't have a summary. This setting can be overriden for each section with the `extra.fullarticles` field.
# Customization
## Extending templates
@ -150,12 +154,45 @@ Then, you need to create templates for the taxonomies in your site's templates f
The variables you can use in those templates are described on [zola docs](https://www.getzola.org/documentation/templates/taxonomies/). Please be aware that taxonomy templates have no title/content or related section/page variables.
**Note**: If your taxonomy template extends the theme's index.html, your site will crash if the template does not override the main block, as the one provided in index.html is intended for the homepage. This could be improved in the future, and patches are welcome!
**WARNING**: Taxonomies templates don't have a lang in Zola <= 10.1. If you are running Zola 10.1, please be sure to override the header block in your taxonomies templates or you will have a friendly error message displayed on your site (no crash).
**Note**: If your taxonomy template extends the theme's index.html, your site will crash if the template does not override the main block, as the one provided in index.html is intended for the homepage. This could be improved in the future, and patches are welcome! **TODO**: check if that is still true with newer zola
**Note**: If you replace the theme's index.html entirely, please remember to include fallbacks for missing variables in taxonomies. These workarounds are marked "TAXONOMY" in the index.html so you can find them easily.
### List of terms
To list the terms in a taxonomy, you may use a template like this:
```
{% extends "index.html" %}
{% block title %}{{ taxonomy.name }} | {{ config.extra.title }}{% endblock %}
{% block main %}
{% if terms %}
<h1>Kinds of {{ taxonomy.name }}:</h1>
<ul>{% for term in terms %}
<li><a href="{{ term.permalink }}">{{ term.name }}</a></li>{% endfor %}
</ul>
{% else %}No terms yet in taxonomy {{ taxonomy.name }}
{% endif %}
{% endblock main %}
```
### List of entries for a term
To list the entries marked for a term, you may use a template like this:
```
{% extends 'index.html' %}
{% block title %}{{ term.name }} | {{ config.extra.title }}{% endblock %}
{% block main %}
{# HACK: cur_paginator doesn't exist on taxonomy terms without enough items #}
<h1>List of articles in {{ taxonomy.name }} {{ term.name }}:</h1>
{{ widgets::section(cur_paginator=paginator|default(value=false), cur_pages=term.pages, full_articles=false) }}
```
# Translations for multilingual sites (i18n)
In order to support translations, you need to enable languages in your site config. Then, you can translate markdown files by simply adding ".LANG" before the ".md" extension, where LANG is the language you want to translate it into. For example, `content/about.md` becomes `content/about.fr.md` in french. This is explained [in the multilingual docs](https://www.getzola.org/documentation/content/multilingual/) on Zola's website.

View File

@ -39,8 +39,8 @@
{% block main %}
{# TAXONOMY: Please override me or i will crash your site #}
{% if config.extra.home_section %}
{% set home_section = config.extra.home_section ~ "/_index.md" %}
{{ widgets::section(cur_section=get_section(path=widgets::i18n_path(path=home_section)), full_articles=config.extra.home_fullarticles, title=config.extra.home_title) }}
{% set home_section = config.extra.home_section ~ "/_index.md" %}{% set i18n_home_section = get_section(path=widgets::i18n_path(path=home_section)) %}
{{ widgets::section(cur_section=i18n_home_section, full_articles=config.extra.home_fullarticles, title=config.extra.home_title, cur_pages=i18n_home_section) }}
{% else %}
{% if config.extra.home_title %}<h1 class="p-name">{{ section.title }}</h1>{% endif %}
{{ section.content | markdown | safe }}

View File

@ -7,7 +7,7 @@
<div>
<h1 class="p-name">{{ page.title }}</h1>
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=trans(key="dateFormat")) }}</time>{%- endif -%}
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::t(key="dateFormat")) }}</time>{%- endif -%}
</div>
<div class="e-content">{{ page.content | safe }}</div>
</article>

View File

@ -4,5 +4,5 @@
{% block main %}
{# HACK: paginator is not set on transparent sections (i.e. blog/2020/_index.md) #}
{{ widgets::section(cur_section=section, cur_paginator=paginator|default(value=false)) }}
{{ widgets::section(cur_section=section, cur_paginator=paginator|default(value=false), cur_pages=section.pages, full_articles=section.extra.fullarticles|default(value=config.section_fullarticles|default(value=false))) }}
{% endblock main %}

View File

@ -80,8 +80,9 @@ Separate entries with a thematic break:
{# Need to use separate names for variables, otherwise the paginator
collides with that of index.html. Also, full_articles and section_title
are useful to home section #}
{% macro section(cur_section, cur_paginator=false, full_articles=true, title=true) %}
{% macro section(cur_section=false, cur_paginator=false, full_articles=true, title=true, cur_pages) %}
<section class="h-feed">
{% if cur_section %}{# Section presentation #}
{% if title %}
<h1>
<span class="p-name">{{ cur_section.title }}</span>{% if cur_paginator and cur_paginator.number_pagers > 1 %} ({{ cur_paginator.current_index }}/{{ cur_paginator.number_pagers }}){% endif %}
@ -89,10 +90,16 @@ Separate entries with a thematic break:
{% endif %}
{# Even if called from a different section (such as homepage), we want the semantic permalink to the collection to match the content #}
<a class="u-url" hidden aria-hidden=true href="{{ cur_section.permalink }}">Permalink</a>
{% set pages = cur_paginator.pages| default(value=cur_section.pages) %}
{% endif %}{# End of section presentation #}
{% set pages = cur_paginator.pages| default(value=cur_pages) %}
{% if pages|length < 1 %}
<center><h2>{{ self::t(key="nothing_yet") }}</h2></center>
{% endif %}
{% if cur_section.content %}
<aside>
{{ cur_section.content | safe }}
</aside>
{% endif %}
{% for page in pages %}
<article>
<div>