142 lines
5.7 KiB
HTML
142 lines
5.7 KiB
HTML
{######################################
|
|
menu widget
|
|
|
|
Provide the widget with a content page
|
|
that contains your menu:
|
|
|
|
{{ widgets::menu(content="_common/menus/main.md") }}
|
|
|
|
Separate entries with a thematic break:
|
|
either ---, ~~~, ___ or <hr />
|
|
|
|
You cannot use <p> tags in the menu.
|
|
That's because we can't access raw markdown
|
|
######################################}
|
|
{% macro menu(path) %}
|
|
<nav class="widget-menu" role="navigation">
|
|
{%- set source = self::i18n_content(path=path) -%}
|
|
{% set entries = source | split(pat="<hr />") %}
|
|
{#- fetch page content and divide it with separator -#}
|
|
{%- for entry in entries %}
|
|
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}
|
|
{# strip paragraph tags away for nicer markup #}
|
|
{%- endfor %}
|
|
</nav>
|
|
{% endmacro menu %}
|
|
|
|
{% macro columns(path) %}
|
|
<div class="widget-columns">
|
|
{%- set source = self::i18n_content(path=path) -%}
|
|
{% set entries = source | split(pat="<hr />") %}
|
|
{#- fetch page content and divide it with separator -#}
|
|
{%- for entry in entries %}
|
|
<div class="widget-columns-column">
|
|
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}
|
|
{# strip paragraph tags away for nicer markup #}
|
|
</div>
|
|
{%- endfor %}
|
|
</div>
|
|
{% endmacro columns %}
|
|
|
|
{%- macro i18n_path(path) -%}
|
|
{% if lang == config.default_language %}{{ path }}
|
|
{%- else -%}
|
|
{%- set parts = path | split(pat=".md") -%}
|
|
{%- for part in parts -%}
|
|
{%- if part and not loop.first -%}.md{%- endif -%}
|
|
{%- if not loop.last -%}{{ part }}{%- endif -%}
|
|
{%- endfor -%}
|
|
.{{ lang }}.md
|
|
{%- endif -%}
|
|
{%- endmacro i18n_path -%}
|
|
|
|
{%- macro i18n_content(path) -%}
|
|
{{ get_page(path=self::i18n_path(path=path)) | get(key="content") }}
|
|
{%- endmacro i18n_content -%}
|
|
|
|
{%- macro i18n_url(path) -%}
|
|
{%- if lang == config.default_language -%}{{ get_url(path=path) }}
|
|
{%- else -%}
|
|
{%- set p = lang ~ "/" ~ path -%}{{ get_url(path=p) }}{%- endif -%}
|
|
{%- endmacro i18n_url -%}
|
|
|
|
{% macro translations(translations) %}
|
|
({{ lang }}){% for t in translations %}{% if lang != t.lang %} <a href="{{ t.permalink }}">{{ t.lang }}</a>{% endif %}{% endfor %}
|
|
{% endmacro translations %}
|
|
|
|
{%- macro strip_lang_from_path(path, lang) -%}
|
|
{%- set lang_path = lang ~ '/' -%}
|
|
{%- if path is starting_with(lang_path) -%}
|
|
{%- if path == lang_path -%}
|
|
{%- set found_lang = true -%}
|
|
{%- set path = "" -%}
|
|
{%- else -%}
|
|
{%- set path = path | replace(from=lang_path, to='') %}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{% if path != '/' %}{{ path }}{% endif %}
|
|
{%- endmacro strip_lang_from_path -%}
|
|
|
|
{# 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=false, cur_paginator=false, full_articles=true, title=true, cur_pages, render_list=true) %}
|
|
<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 %}
|
|
</h1>
|
|
{% 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>
|
|
{% endif %}{# End of section presentation #}
|
|
{% set pages = cur_paginator.pages| default(value=cur_pages) %}
|
|
{% if pages|length < 1 and render_list %}
|
|
<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>
|
|
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
|
|
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅 {{ page.date | date(format=self::t(key="dateFormat")) }}</time>{%- endif -%}
|
|
</div>
|
|
{% if page.summary %}
|
|
<div class="p-summary e-content">
|
|
{{ page.summary | markdown | safe }}
|
|
<a class="read-more" href="{{ page.permalink }}">--> {{ self::t(key="readmore") }} <--</a>
|
|
</div>
|
|
{% elif full_articles %}
|
|
<div class="e-content">
|
|
{{ page.content | markdown | safe }}
|
|
</div>
|
|
{% endif %}
|
|
</article>
|
|
{% endfor %}
|
|
{% if cur_paginator and cur_paginator.number_pagers > 1 %}
|
|
<aside class="pagination">
|
|
{% if cur_paginator.previous %}
|
|
<a href="{{ cur_paginator.previous }}"><-- {{ self::t(key="previousPage") }}</a>
|
|
{% endif %}
|
|
{% if cur_paginator.next %}
|
|
<a href="{{ cur_paginator.next }}">{{ self::t(key="nextPage") }} --></a>
|
|
{% endif %}
|
|
</aside>
|
|
{% endif %}
|
|
</section>
|
|
{% endmacro section %}
|
|
|
|
{# Translate a string in the current language (lang) by looking
|
|
up a key in the config.extra.translations.lang. These translation
|
|
strings extend (and potentially replace) those of the theme. #}
|
|
{%- macro t(key) -%}
|
|
{%- if config.extra.missing_translations|default(value="error") == "error" -%}{{ config.extra.translations[lang][key] }}
|
|
{%- elif config.extra.missing_translations == "placeholder" -%}{{ config.extra.translations[lang][key]|default(value=key) }}
|
|
{%- else -%}{{ config.extra.translations[lang][key]|default(value=config.extra.translations[config.extra.missing_translations][key]) }}{%- endif -%}
|
|
{%- endmacro t -%}
|