Skip to content
Snippets Groups Projects
Verified Commit b62e0e81 authored by Jake's avatar Jake :speech_balloon:
Browse files

improved menu rendering

parent 8c33aafa
No related branches found
No related tags found
No related merge requests found
Pipeline #313231 passed
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
{%- import 'macros/cards.html' as cards with context -%} {%- import 'macros/cards.html' as cards with context -%}
{%- import 'macros/renderers.html' as render with context -%} {%- import 'macros/renderers.html' as render with context -%}
{%- import 'macros/content_renderer.html' as content_renderer with context -%} {%- import 'macros/content_renderer.html' as content_renderer with context -%}
{%- import 'macros/nav.html' as nav with context -%}
<html lang="{%- block html_lang -%}{{ l }}{%- endblock html_lang -%}"> <html lang="{%- block html_lang -%}{{ l }}{%- endblock html_lang -%}">
<head> <head>
...@@ -40,28 +41,7 @@ ...@@ -40,28 +41,7 @@
<label for="show-header-menu" class="show-header-menu">&#9776;</label> <label for="show-header-menu" class="show-header-menu">&#9776;</label>
<input type="checkbox" id="show-header-menu" role="button"> <input type="checkbox" id="show-header-menu" role="button">
<label for="show-header-menu" class="show-header-menu-bg"> </label> <label for="show-header-menu" class="show-header-menu-bg"> </label>
<nav> {{ nav.render_menu(config.menuitems, l) }}
<ul>
{% for item in config.menuitems -%}
{%- if item.tag is defined -%}
{%- call(tagtitle, tagcolor, tagurl, tagpage, tagpages) get.tag_by_name(item.tag, l) -%}
<li style="--category-color: {{ tagcolor }}"><a href="{{ siteurl }}/{{ tagurl }}">{{ tagtitle|e }}</a></li>
{%- endcall -%}
{%- elif item.slug is defined -%}
{%- call(page) get.page_by_slug(item.slug, l) -%}
{%- call(cattitle, catcolor, caturl, catpage, catpages) get.tag_by_name(page.category, l) -%}
<li style="--category-color: {{ catcolor }}"><a href="{{ siteurl }}/{{ page.url }}">{{ page.title|e }}</a></li>
{%- endcall -%}
{%- endcall -%}
{%- else -%}
<br />
<strong>ERROR: menuitems: Cannot parse item: {{ item|string|e }}</strong><br />
<br />
{%- endif -%}
{#- TODO add active class if this is the current site -#}
{%- endfor %}
</ul>
</nav>
</div> </div>
<main> <main>
{% block content %} {% block content %}
......
{%- import 'macros/link.html' as link with context -%}
{%- macro render_menu(items, lang) -%}
<nav>
<ul>
{% for item in items -%}
{{ render_menu_item(item, lang) }}
{%- endfor %}
</ul>
</nav>
{%- endmacro -%}
{%- macro render_menu_item(item, lang) -%}
{%- if item is string -%}
{%- set url = item -%}
{%- call(parsedurl, anchor, reflang, is_external, reftype, refid, refpage, tagcattitle, tagcatcolor) link.parse_url(url, lang) -%}
<li style="--category-color: {{ tagcatcolor }}">
{{ link.render(url, None, lang) }}
</li>
{%- endcall -%}
{%- else -%}
TODO: handle custom menu items
{%- endif -%}
{%- endmacro -%}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment