zola-theme-terminimal/templates/macros/menu.html

34 lines
1.5 KiB
HTML
Raw Normal View History

2019-02-05 19:27:02 +01:00
{% macro menu(config, current_path) %}
{%- if config.extra.menu_items %}
{%- set menu_items = config.extra.menu_items -%}
<nav class="menu">
<ul class="menu__inner">
{%- for item in menu_items %}
2019-02-05 20:13:23 +01:00
{%- set rel_item_url = item.url | replace(from="$BASE_URL", to="") -%}
{%- set current = rel_item_url == current_path
or rel_item_url == "/" ~ current_path
or rel_item_url ~ "/" == "/" ~ current_path
or rel_item_url == "" and current_path == "/"
2019-02-05 19:27:02 +01:00
-%}
{%- if current %}
{%- set_global current_item = item -%}
{% endif -%}
{% endfor -%}
{%- for item in menu_items %}
{%- set blog_post = not current_item and item.url == "/" -%}
<li {%- if current_item and item == current_item or blog_post %} class="active" {%- endif %}>
{%- if item.newtab -%}
2019-02-05 20:13:23 +01:00
<a href="{{ item.url | replace(from="$BASE_URL", to=config.base_url) | safe }}" target="_blank" rel="noopener noreferrer">{{ item.name | safe }}</a>
2019-02-05 19:27:02 +01:00
{%- else -%}
2019-02-05 20:13:23 +01:00
<a href="{{ item.url | replace(from="$BASE_URL", to=config.base_url) | safe }}">{{ item.name | safe }}</a>
2019-02-05 19:27:02 +01:00
{%- endif -%}
</li>
{% endfor -%}
</ul>
</nav>
{% endif -%}
{% endmacro menu %}