website/templates/widgets.html
2020-04-01 16:43:40 +02:00

68 lines
2.2 KiB
HTML

{######################################
menu widget
Provide the widget with a content page
that contains your menu:
{{ widgets::menu(content="_common/menus/main.md") }}
If the content page has a translation, it will be
automatically loaded in the current language, as long as
your parent template has a `lang` variable set, like so:
{% set lang = section.lang | default(value=page.lang) %}
Separate entries with a thematic break:
either ---, ~~~, ___ or <hr />
An entry can be either text, a link, or
a submenu. A submenu is an actual list
defined using Markdown or HTML.
You cannot use <p> tags in the menu.
######################################}
{% macro menu(content) %}
<nav class="nav-menu" role="navigation">
{%- set source = self::i18n_content(path=content) -%}
{% 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 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 %}<a href="{{ t.permalink }}">{{ t.lang }}</a>{% endfor %}
{% endmacro translations %}
{% macro bubble(content, v="bottom", h="right") %}
<div class="widget-bubble widget-bubble-{{ v }} widget-bubble-{{ h }}">
<div class="widget-bubble-arrow"></div>
{{ content | safe }}
</div>
{% endmacro bubble %}