Simplified conditionals in templates

This commit is contained in:
squidfunk 2020-11-07 16:09:06 +01:00
parent a46b42c5e2
commit acc4a273c4
5 changed files with 31 additions and 59 deletions

View File

@ -7,11 +7,8 @@
{% endif %}
{% if nav_item.children %}
<li class="{{ class }} md-nav__item--nested">
{% if nav_item.active %}
<input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}" checked>
{% else %}
<input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}">
{% endif %}
{% set checked = "checked" if nav_item.active %}
<input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}" {{ checked }}>
<label class="md-nav__link" for="{{ path }}">
{{ nav_item.title }}
<span class="md-nav__icon md-icon"></span>

View File

@ -3,15 +3,13 @@
-#}
{% if nav_item.is_homepage or nav_item.url == "index.html" %}
<li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if not page.ancestors | length and nav | selectattr("url", page.url) %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link md-tabs__link--active">
{{ nav_item.title }}
</a>
{% else %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link">
{{ nav_item.title }}
</a>
{% set class = "md-tabs__link md-tabs__link--active" %}
{% endif %}
<a href="{{ nav_item.url | url }}" class="{{ class }}">
{{ nav_item.title }}
</a>
</li>
{% elif nav_item.children and nav_item.children | length > 0 %}
{% set title = title | default(nav_item.title) %}
@ -20,15 +18,13 @@
{% include "partials/tabs-item.html" %}
{% else %}
<li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if nav_item.active %}
<a href="{{ (nav_item.children | first).url | url }}" class="md-tabs__link md-tabs__link--active">
{{ title }}
</a>
{% else %}
<a href="{{ (nav_item.children | first).url | url }}" class="md-tabs__link">
{{ title }}
</a>
{% set class = "md-tabs__link md-tabs__link--active" %}
{% endif %}
<a href="{{ (nav_item.children | first).url | url }}" class="{{ class }}">
{{ title }}
</a>
</li>
{% endif %}
{% elif nav_item.url.startswith("http") %}

View File

@ -31,22 +31,14 @@
<li class="{{ class }} md-nav__item--nested">
<!-- Active checkbox expands items contained within nested section -->
{% if nav_item.active %}
<input
class="md-nav__toggle md-toggle"
data-md-toggle="{{ path }}"
type="checkbox"
id="{{ path }}"
checked
/>
{% else %}
<input
class="md-nav__toggle md-toggle"
data-md-toggle="{{ path }}"
type="checkbox"
id="{{ path }}"
/>
{% endif %}
{% set checked = "checked" if nav_item.active %}
<input
class="md-nav__toggle md-toggle"
data-md-toggle="{{ path }}"
type="checkbox"
id="{{ path }}"
{{ checked }}
/>
<!-- Expand active pages -->
<label class="md-nav__link" for="{{ path }}">

View File

@ -22,7 +22,7 @@
{% import "partials/language.html" as lang with context %}
<!-- Support for mkdocs-git-revision-date-localized-plugin -->
<!-- Last updated date -->
{% set label = lang.t("source.revision.date") %}
<hr />
<div class="md-source-date">

View File

@ -23,18 +23,13 @@
<!-- Home page -->
{% if nav_item.is_homepage or nav_item.url == "index.html" %}
<li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if not page.ancestors | length and nav | selectattr("url", page.url) %}
<a
href="{{ nav_item.url | url }}"
class="md-tabs__link md-tabs__link--active"
>
{{ nav_item.title }}
</a>
{% else %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link">
{{ nav_item.title }}
</a>
{% set class = "md-tabs__link md-tabs__link--active" %}
{% endif %}
<a href="{{ nav_item.url | url }}" class="{{ class }}">
{{ nav_item.title }}
</a>
</li>
<!-- Main navigation item with nested items -->
@ -49,21 +44,13 @@
<!-- Render item -->
{% else %}
<li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if nav_item.active %}
<a
href="{{ (nav_item.children | first).url | url }}"
class="md-tabs__link md-tabs__link--active"
>
{{ title }}
</a>
{% else %}
<a
href="{{ (nav_item.children | first).url | url }}"
class="md-tabs__link"
>
{{ title }}
</a>
{% set class = "md-tabs__link md-tabs__link--active" %}
{% endif %}
<a href="{{ (nav_item.children | first).url | url }}" class="{{ class }}">
{{ title }}
</a>
</li>
{% endif %}