Fixed last minijinja compat issues in templates

This commit is contained in:
squidfunk
2025-08-16 11:11:40 +02:00
parent c89a66bf39
commit c79364a7e0
6 changed files with 89 additions and 54 deletions

View File

@@ -3,7 +3,7 @@
-#}
{% include "partials/tags.html" %}
{% include "partials/actions.html" %}
{% if "\x3ch1" not in page.content %}
{% if "\u003ch1" not in page.content %}
<h1>{{ page.title | d(config.site_name, true)}}</h1>
{% endif %}
{{ page.content }}

View File

@@ -2,21 +2,23 @@
This file was automatically generated - do not edit
-#}
{% if config.theme.icon.admonition %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% for type, icon in config.theme.icon.admonition | items %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-admonition-icon--" ~ type ~ ":" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');"
%}
{% if type and icon %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-admonition-icon--" ~ type ~ ":" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');"
%}
{% endif %}
{% endfor %}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}
{% if config.theme.icon.annotation %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-annotation-icon:" ~
@@ -24,25 +26,27 @@
icon | replace("\n", "") | urlencode ~
"');"
%}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}
{% if config.theme.icon.tag %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% for type, icon in config.theme.icon.tag | items %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% if type != "default" %}
{% set modifier = ".md-tag--" ~ type %}
{% if type and icon %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% if type != "default" %}
{% set modifier = ".md-tag--" ~ type %}
{% endif %}
{% set _.style = _.style ~
".md-tag" ~ modifier ~ "{" ~
"--md-tag-icon:" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');" ~
"}"
%}
{% endif %}
{% set _.style = _.style ~
".md-tag" ~ modifier ~ "{" ~
"--md-tag-icon:" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');" ~
"}"
%}
{% endfor %}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}

View File

@@ -1,6 +1,14 @@
{#-
This file was automatically generated - do not edit
-#}
{% macro split_and_get(value, sep, index) %}
{%- if value.split is defined -%}
{%- set parts = value.split(sep) -%}
{%- else -%}
{%- set parts = value | split(sep) -%}
{%- endif -%}
{{- parts[index] -}}
{% endmacro %}
<div class="md-social">
{% for social in config.extra.social %}
{% set rel = "noopener" %}
@@ -9,8 +17,8 @@
{% endif %}
{% set title = social.name %}
{% if not title and "//" in social.link %}
{% set (_, url) = social.link.split("//") %}
{% set title = url.split("/") | first %}
{% set url = split_and_get(social.link, "//", 1) %}
{% set title = split_and_get(url, "/", 0) %}
{% endif %}
<a href="{{ social.link }}" target="_blank" rel="{{ rel }}" title="{{ title | e }}" class="md-social__link">
{% include ".icons/" ~ social.icon ~ ".svg" %}

View File

@@ -30,7 +30,7 @@
Hack: check whether the content contains a h1 headline. If it doesn't, the
page title (or respectively site name) is used as the main headline.
-->
{% if "\x3ch1" not in page.content %}
{% if "\u003ch1" not in page.content %}
<h1>{{ page.title | d(config.site_name, true)}}</h1>
{% endif %}

View File

@@ -22,23 +22,25 @@
<!-- Custom admonition icons -->
{% if config.theme.icon.admonition %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% for type, icon in config.theme.icon.admonition | items %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-admonition-icon--" ~ type ~ ":" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');"
%}
{% if type and icon %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-admonition-icon--" ~ type ~ ":" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');"
%}
{% endif %}
{% endfor %}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}
<!-- Custom annotation icon -->
{% if config.theme.icon.annotation %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %}
{% set _.style = _.style ~
"--md-annotation-icon:" ~
@@ -46,27 +48,29 @@
icon | replace("\n", "") | urlencode ~
"');"
%}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}
<!-- Custom tag icons -->
{% if config.theme.icon.tag %}
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
{% for type, icon in config.theme.icon.tag | items %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% if type != "default" %}
{% set modifier = ".md-tag--" ~ type %}
{% if type and icon %}
{% import ".icons/" ~ icon ~ ".svg" as icon %}
{% if type != "default" %}
{% set modifier = ".md-tag--" ~ type %}
{% endif %}
{% set _.style = _.style ~
".md-tag" ~ modifier ~ "{" ~
"--md-tag-icon:" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');" ~
"}"
%}
{% endif %}
{% set _.style = _.style ~
".md-tag" ~ modifier ~ "{" ~
"--md-tag-icon:" ~
"url('data:image/svg+xml;charset=utf-8," ~
icon | replace("\n", "") | urlencode ~
"');" ~
"}"
%}
{% endfor %}
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
{{ _.style }}
{% endif %}

View File

@@ -20,6 +20,25 @@
IN THE SOFTWARE.
-->
<!--
Split a string with a separator - while Jinja allows to call ".split" on a
string, it doesn't natively bring a "split" filter implementation. We can't
simply add further filters, since MkDocs doesn't allow it, so we're stuck
with the function call. This however doesn't work with minijinja, which does
not allow to call functions on template variables, but has a "split" filter.
Thus, we just branch and extract the part that interests us here.
-->
{% macro split_and_get(value, sep, index) %}
{%- if value.split is defined -%}
{%- set parts = value.split(sep) -%}
{%- else -%}
{%- set parts = value | split(sep) -%}
{%- endif -%}
{{- parts[index] -}}
{% endmacro %}
<!-- ---------------------------------------------------------------------- -->
<!-- Social links -->
<div class="md-social">
{% for social in config.extra.social %}
@@ -33,8 +52,8 @@
<!-- Compute title and render link -->
{% set title = social.name %}
{% if not title and "//" in social.link %}
{% set (_, url) = social.link.split("//") %}
{% set title = url.split("/") | first %}
{% set url = split_and_get(social.link, "//", 1) %}
{% set title = split_and_get(url, "/", 0) %}
{% endif %}
<a
href="{{ social.link }}"