From ec38e30daf741777563f42ee2243edf208e51ace Mon Sep 17 00:00:00 2001 From: squidfunk Date: Tue, 25 Mar 2025 13:10:32 +0100 Subject: [PATCH] Ensured compatibility with minijinja (Rust) --- material/templates/base.html | 54 +++++++-------- material/templates/partials/consent.html | 59 ++++++++-------- material/templates/partials/feedback.html | 7 +- material/templates/partials/icons.html | 34 ++++----- material/templates/partials/nav-item.html | 20 +++--- material/templates/partials/social.html | 4 +- material/templates/partials/source-file.html | 4 +- material/templates/partials/tabs-item.html | 6 +- src/templates/base.html | 60 ++++++++-------- src/templates/partials/consent.html | 73 ++++++++++++-------- src/templates/partials/feedback.html | 7 +- src/templates/partials/icons.html | 34 ++++----- src/templates/partials/nav-item.html | 20 +++--- src/templates/partials/social.html | 4 +- src/templates/partials/source-file.html | 4 +- src/templates/partials/tabs-item.html | 6 +- 16 files changed, 213 insertions(+), 183 deletions(-) diff --git a/material/templates/base.html b/material/templates/base.html index d3e958b00..7737b5d0d 100644 --- a/material/templates/base.html +++ b/material/templates/base.html @@ -58,8 +58,8 @@ {% endblock %} {% block fonts %} {% if config.theme.font != false %} - {% set text = config.theme.font.get("text", "Roboto") %} - {% set code = config.theme.font.get("code", "Roboto Mono") %} + {% set text = config.theme.font.text | d("Roboto", true) %} + {% set code = config.theme.font.code | d("Roboto Mono", true) %} - {{- app | tojson -}} + {{- { + "base": base_url, + "features": features, + "translations": { + "clipboard.copy": lang.t("clipboard.copy"), + "clipboard.copied": lang.t("clipboard.copied"), + "search.result.placeholder": lang.t("search.result.placeholder"), + "search.result.none": lang.t("search.result.none"), + "search.result.one": lang.t("search.result.one"), + "search.result.other": lang.t("search.result.other"), + "search.result.more.one": lang.t("search.result.more.one"), + "search.result.more.other": lang.t("search.result.more.other"), + "search.result.term.missing": lang.t("search.result.term.missing"), + "select.version": lang.t("select.version") + }, + "search": "assets/javascripts/workers/search.f8cc74c7.min.js" | url, + "tags": _.tags or none, + "version": _.version or none + } | tojson -}} {% endblock %} {% block scripts %} diff --git a/material/templates/partials/consent.html b/material/templates/partials/consent.html index 4ac5cb775..45bd22c6a 100644 --- a/material/templates/partials/consent.html +++ b/material/templates/partials/consent.html @@ -1,17 +1,25 @@ {#- This file was automatically generated - do not edit -#} -{% set cookies = config.extra.consent.cookies | d({}) %} -{% if config.extra.analytics %} - {% if "analytics" not in cookies %} - {% set _ = cookies.update({ "analytics": "Google Analytics" }) %} +{% macro render_cookie(cookie, type) %} + {% set checked = "" %} + {% if cookie is string %} + {% set name = cookie %} + {% set checked = "checked" %} + {% else %} + {% set name = cookie.name %} + {% if cookie.checked %} + {% set checked = "checked" %} + {% endif %} {% endif %} -{% endif %} -{% if config.repo_url and "github.com" in config.repo_url %} - {% if "github" not in cookies %} - {% set _ = cookies.update({ "github": "GitHub" }) %} - {% endif %} -{% endif %} +
  • + +
  • +{% endmacro %} {% set actions = config.extra.consent.actions %} {% if not actions %} {% set actions = ["accept", "manage"] %} @@ -24,24 +32,21 @@ diff --git a/material/templates/partials/feedback.html b/material/templates/partials/feedback.html index 2cde98c75..b7c4b9d86 100644 --- a/material/templates/partials/feedback.html +++ b/material/templates/partials/feedback.html @@ -32,7 +32,12 @@ {% else %} {% set title = page.title | urlencode %} {% endif %} - {{ rating.note.format(url = url, title = title) }} + {% set note = rating.note %} + {% if note %} + {% set note = note | replace("{url}", url) %} + {% set note = note | replace("{title}", title) %} + {% endif %} + {{ note }} {% endfor %} diff --git a/material/templates/partials/icons.html b/material/templates/partials/icons.html index 37da7364f..7d3aaded0 100644 --- a/material/templates/partials/icons.html +++ b/material/templates/partials/icons.html @@ -2,47 +2,47 @@ This file was automatically generated - do not edit -#} {% if config.theme.icon.admonition %} - {% set style = ["\x3cstyle\x3e:root{"] %} - {% for type, icon in config.theme.icon.admonition.items() %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} + {% for type, icon in config.theme.icon.admonition | items %} {% import ".icons/" ~ icon ~ ".svg" as icon %} - {% set _ = style.append( + {% set _.style = _.style ~ "--md-admonition-icon--" ~ type ~ ":" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" - ) %} + %} {% endfor %} - {% set _ = style.append("}\x3c/style\x3e") %} - {{ style | join }} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} {% if config.theme.icon.annotation %} - {% set style = ["\x3cstyle\x3e:root{"] %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} {% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %} - {% set _ = style.append( + {% set _.style = _.style ~ "--md-annotation-icon:" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" - ) %} - {% set _ = style.append("}\x3c/style\x3e") %} - {{ style | join }} + %} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} {% if config.theme.icon.tag %} - {% set style = ["\x3cstyle\x3e"] %} - {% for type, icon in config.theme.icon.tag.items() %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} + {% for type, icon in config.theme.icon.tag | items %} {% import ".icons/" ~ icon ~ ".svg" as icon %} {% if type != "default" %} {% set modifier = ".md-tag--" ~ type %} {% endif %} - {% set _ = style.append( + {% set _.style = _.style ~ ".md-tag" ~ modifier ~ "{" ~ "--md-tag-icon:" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" ~ "}" - ) %} + %} {% endfor %} - {% set _ = style.append("\x3c/style\x3e") %} - {{ style | join }} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} diff --git a/material/templates/partials/nav-item.html b/material/templates/partials/nav-item.html index a0bcdcfb9..d7050dd7f 100644 --- a/material/templates/partials/nav-item.html +++ b/material/templates/partials/nav-item.html @@ -10,7 +10,8 @@ {% endif %} {% endmacro %} -{% macro render_content(nav_item, ref = nav_item) %} +{% macro render_content(nav_item, ref) %} + {% set ref = ref or nav_item %} {% if nav_item.meta and nav_item.meta.icon %} {% include ".icons/" ~ nav_item.meta.icon ~ ".svg" %} {% endif %} @@ -25,7 +26,8 @@ {{ render_status(nav_item, nav_item.meta.status) }} {% endif %} {% endmacro %} -{% macro render_pruned(nav_item, ref = nav_item) %} +{% macro render_pruned(nav_item, ref) %} + {% set ref = ref or nav_item %} {% set first = nav_item.children | first %} {% if first and first.children %} {{ render_pruned(first, ref) }} @@ -49,14 +51,15 @@ {% endif %} {% endif %} {% if nav_item.children %} - {% set indexes = [] %} + {% set _ = namespace(index = none) %} {% if "navigation.indexes" in features %} - {% for nav_item in nav_item.children %} - {% if nav_item.is_index and not index is defined %} - {% set _ = indexes.append(nav_item) %} + {% for item in nav_item.children %} + {% if item.is_index and _.index is none %} + {% set _.index = item %} {% endif %} {% endfor %} {% endif %} + {% set index = _.index %} {% if "navigation.tabs" in features %} {% if level == 1 and nav_item.active %} {% set class = class ~ " md-nav__item--section" %} @@ -87,14 +90,13 @@ {% set indeterminate = "md-toggle--indeterminate" %} {% endif %} - {% if not indexes %} + {% if not index %} {% set tabindex = "0" if not is_section %} {% else %} - {% set index = indexes | first %} {% set class = "md-nav__link--active" if index == page %} {% endfor %} diff --git a/src/templates/partials/icons.html b/src/templates/partials/icons.html index 2f267a229..c18cea364 100644 --- a/src/templates/partials/icons.html +++ b/src/templates/partials/icons.html @@ -22,51 +22,51 @@ {% if config.theme.icon.admonition %} - {% set style = ["\x3cstyle\x3e:root{"] %} - {% for type, icon in config.theme.icon.admonition.items() %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} + {% for type, icon in config.theme.icon.admonition | items %} {% import ".icons/" ~ icon ~ ".svg" as icon %} - {% set _ = style.append( + {% set _.style = _.style ~ "--md-admonition-icon--" ~ type ~ ":" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" - ) %} + %} {% endfor %} - {% set _ = style.append("}\x3c/style\x3e") %} - {{ style | join }} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} {% if config.theme.icon.annotation %} - {% set style = ["\x3cstyle\x3e:root{"] %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} {% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %} - {% set _ = style.append( + {% set _.style = _.style ~ "--md-annotation-icon:" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" - ) %} - {% set _ = style.append("}\x3c/style\x3e") %} - {{ style | join }} + %} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} {% if config.theme.icon.tag %} - {% set style = ["\x3cstyle\x3e"] %} - {% for type, icon in config.theme.icon.tag.items() %} + {% set _ = namespace(style = "\x3cstyle\x3e:root{") %} + {% for type, icon in config.theme.icon.tag | items %} {% import ".icons/" ~ icon ~ ".svg" as icon %} {% if type != "default" %} {% set modifier = ".md-tag--" ~ type %} {% endif %} - {% set _ = style.append( + {% set _.style = _.style ~ ".md-tag" ~ modifier ~ "{" ~ "--md-tag-icon:" ~ "url('data:image/svg+xml;charset=utf-8," ~ icon | replace("\n", "") | urlencode ~ "');" ~ "}" - ) %} + %} {% endfor %} - {% set _ = style.append("\x3c/style\x3e") %} - {{ style | join }} + {% set _.style = _.style ~ "}\x3c/style\x3e" %} + {{ _.style }} {% endif %} diff --git a/src/templates/partials/nav-item.html b/src/templates/partials/nav-item.html index 96349f524..12d4e69ba 100644 --- a/src/templates/partials/nav-item.html +++ b/src/templates/partials/nav-item.html @@ -39,7 +39,8 @@ {% endmacro %} -{% macro render_content(nav_item, ref = nav_item) %} +{% macro render_content(nav_item, ref) %} + {% set ref = ref or nav_item %} {% if nav_item.meta and nav_item.meta.icon %} @@ -64,7 +65,8 @@ {% endmacro %} -{% macro render_pruned(nav_item, ref = nav_item) %} +{% macro render_pruned(nav_item, ref) %} + {% set ref = ref or nav_item %} {% set first = nav_item.children | first %} @@ -104,14 +106,15 @@ {% if nav_item.children %} - {% set indexes = [] %} + {% set _ = namespace(index = none) %} {% if "navigation.indexes" in features %} - {% for nav_item in nav_item.children %} - {% if nav_item.is_index and not index is defined %} - {% set _ = indexes.append(nav_item) %} + {% for item in nav_item.children %} + {% if item.is_index and _.index is none %} + {% set _.index = item %} {% endif %} {% endfor %} {% endif %} + {% set index = _.index %} {% if "navigation.tabs" in features %} @@ -171,7 +174,7 @@ /> - {% if not indexes %} + {% if not index %} {% set tabindex = "0" if not is_section %}