Skip to content

Commit c79364a

Browse files
committed
Fixed last minijinja compat issues in templates
1 parent c89a66b commit c79364a

File tree

6 files changed

+89
-54
lines changed

6 files changed

+89
-54
lines changed

material/templates/partials/content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-#}
44
{% include "partials/tags.html" %}
55
{% include "partials/actions.html" %}
6-
{% if "\x3ch1" not in page.content %}
6+
{% if "\u003ch1" not in page.content %}
77
<h1>{{ page.title | d(config.site_name, true)}}</h1>
88
{% endif %}
99
{{ page.content }}

material/templates/partials/icons.html

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,51 @@
22
This file was automatically generated - do not edit
33
-#}
44
{% if config.theme.icon.admonition %}
5-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
5+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
66
{% for type, icon in config.theme.icon.admonition | items %}
7-
{% import ".icons/" ~ icon ~ ".svg" as icon %}
8-
{% set _.style = _.style ~
9-
"--md-admonition-icon--" ~ type ~ ":" ~
10-
"url('data:image/svg+xml;charset=utf-8," ~
11-
icon | replace("\n", "") | urlencode ~
12-
"');"
13-
%}
7+
{% if type and icon %}
8+
{% import ".icons/" ~ icon ~ ".svg" as icon %}
9+
{% set _.style = _.style ~
10+
"--md-admonition-icon--" ~ type ~ ":" ~
11+
"url('data:image/svg+xml;charset=utf-8," ~
12+
icon | replace("\n", "") | urlencode ~
13+
"');"
14+
%}
15+
{% endif %}
1416
{% endfor %}
15-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
17+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
1618
{{ _.style }}
1719
{% endif %}
1820
{% if config.theme.icon.annotation %}
19-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
21+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
2022
{% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %}
2123
{% set _.style = _.style ~
2224
"--md-annotation-icon:" ~
2325
"url('data:image/svg+xml;charset=utf-8," ~
2426
icon | replace("\n", "") | urlencode ~
2527
"');"
2628
%}
27-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
29+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
2830
{{ _.style }}
2931
{% endif %}
3032
{% if config.theme.icon.tag %}
31-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
33+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
3234
{% for type, icon in config.theme.icon.tag | items %}
33-
{% import ".icons/" ~ icon ~ ".svg" as icon %}
34-
{% if type != "default" %}
35-
{% set modifier = ".md-tag--" ~ type %}
35+
{% if type and icon %}
36+
{% import ".icons/" ~ icon ~ ".svg" as icon %}
37+
{% if type != "default" %}
38+
{% set modifier = ".md-tag--" ~ type %}
39+
{% endif %}
40+
{% set _.style = _.style ~
41+
".md-tag" ~ modifier ~ "{" ~
42+
"--md-tag-icon:" ~
43+
"url('data:image/svg+xml;charset=utf-8," ~
44+
icon | replace("\n", "") | urlencode ~
45+
"');" ~
46+
"}"
47+
%}
3648
{% endif %}
37-
{% set _.style = _.style ~
38-
".md-tag" ~ modifier ~ "{" ~
39-
"--md-tag-icon:" ~
40-
"url('data:image/svg+xml;charset=utf-8," ~
41-
icon | replace("\n", "") | urlencode ~
42-
"');" ~
43-
"}"
44-
%}
4549
{% endfor %}
46-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
50+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
4751
{{ _.style }}
4852
{% endif %}

material/templates/partials/social.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{#-
22
This file was automatically generated - do not edit
33
-#}
4+
{% macro split_and_get(value, sep, index) %}
5+
{%- if value.split is defined -%}
6+
{%- set parts = value.split(sep) -%}
7+
{%- else -%}
8+
{%- set parts = value | split(sep) -%}
9+
{%- endif -%}
10+
{{- parts[index] -}}
11+
{% endmacro %}
412
<div class="md-social">
513
{% for social in config.extra.social %}
614
{% set rel = "noopener" %}
@@ -9,8 +17,8 @@
917
{% endif %}
1018
{% set title = social.name %}
1119
{% if not title and "//" in social.link %}
12-
{% set (_, url) = social.link.split("//") %}
13-
{% set title = url.split("/") | first %}
20+
{% set url = split_and_get(social.link, "//", 1) %}
21+
{% set title = split_and_get(url, "/", 0) %}
1422
{% endif %}
1523
<a href="{{ social.link }}" target="_blank" rel="{{ rel }}" title="{{ title | e }}" class="md-social__link">
1624
{% include ".icons/" ~ social.icon ~ ".svg" %}

src/templates/partials/content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
Hack: check whether the content contains a h1 headline. If it doesn't, the
3131
page title (or respectively site name) is used as the main headline.
3232
-->
33-
{% if "\x3ch1" not in page.content %}
33+
{% if "\u003ch1" not in page.content %}
3434
<h1>{{ page.title | d(config.site_name, true)}}</h1>
3535
{% endif %}
3636

src/templates/partials/icons.html

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,55 @@
2222

2323
<!-- Custom admonition icons -->
2424
{% if config.theme.icon.admonition %}
25-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
25+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
2626
{% for type, icon in config.theme.icon.admonition | items %}
27-
{% import ".icons/" ~ icon ~ ".svg" as icon %}
28-
{% set _.style = _.style ~
29-
"--md-admonition-icon--" ~ type ~ ":" ~
30-
"url('data:image/svg+xml;charset=utf-8," ~
31-
icon | replace("\n", "") | urlencode ~
32-
"');"
33-
%}
27+
{% if type and icon %}
28+
{% import ".icons/" ~ icon ~ ".svg" as icon %}
29+
{% set _.style = _.style ~
30+
"--md-admonition-icon--" ~ type ~ ":" ~
31+
"url('data:image/svg+xml;charset=utf-8," ~
32+
icon | replace("\n", "") | urlencode ~
33+
"');"
34+
%}
35+
{% endif %}
3436
{% endfor %}
35-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
37+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
3638
{{ _.style }}
3739
{% endif %}
3840

3941
<!-- Custom annotation icon -->
4042
{% if config.theme.icon.annotation %}
41-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
43+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
4244
{% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %}
4345
{% set _.style = _.style ~
4446
"--md-annotation-icon:" ~
4547
"url('data:image/svg+xml;charset=utf-8," ~
4648
icon | replace("\n", "") | urlencode ~
4749
"');"
4850
%}
49-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
51+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
5052
{{ _.style }}
5153
{% endif %}
5254

5355
<!-- Custom tag icons -->
5456
{% if config.theme.icon.tag %}
55-
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
57+
{% set _ = namespace(style = "\u003cstyle\u003e:root{") %}
5658
{% for type, icon in config.theme.icon.tag | items %}
57-
{% import ".icons/" ~ icon ~ ".svg" as icon %}
58-
{% if type != "default" %}
59-
{% set modifier = ".md-tag--" ~ type %}
59+
{% if type and icon %}
60+
{% import ".icons/" ~ icon ~ ".svg" as icon %}
61+
{% if type != "default" %}
62+
{% set modifier = ".md-tag--" ~ type %}
63+
{% endif %}
64+
{% set _.style = _.style ~
65+
".md-tag" ~ modifier ~ "{" ~
66+
"--md-tag-icon:" ~
67+
"url('data:image/svg+xml;charset=utf-8," ~
68+
icon | replace("\n", "") | urlencode ~
69+
"');" ~
70+
"}"
71+
%}
6072
{% endif %}
61-
{% set _.style = _.style ~
62-
".md-tag" ~ modifier ~ "{" ~
63-
"--md-tag-icon:" ~
64-
"url('data:image/svg+xml;charset=utf-8," ~
65-
icon | replace("\n", "") | urlencode ~
66-
"');" ~
67-
"}"
68-
%}
6973
{% endfor %}
70-
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
74+
{% set _.style = _.style ~ "}\u003c/style\u003e" %}
7175
{{ _.style }}
7276
{% endif %}

src/templates/partials/social.html

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020
IN THE SOFTWARE.
2121
-->
2222

23+
<!--
24+
Split a string with a separator - while Jinja allows to call ".split" on a
25+
string, it doesn't natively bring a "split" filter implementation. We can't
26+
simply add further filters, since MkDocs doesn't allow it, so we're stuck
27+
with the function call. This however doesn't work with minijinja, which does
28+
not allow to call functions on template variables, but has a "split" filter.
29+
Thus, we just branch and extract the part that interests us here.
30+
-->
31+
{% macro split_and_get(value, sep, index) %}
32+
{%- if value.split is defined -%}
33+
{%- set parts = value.split(sep) -%}
34+
{%- else -%}
35+
{%- set parts = value | split(sep) -%}
36+
{%- endif -%}
37+
{{- parts[index] -}}
38+
{% endmacro %}
39+
40+
<!-- ---------------------------------------------------------------------- -->
41+
2342
<!-- Social links -->
2443
<div class="md-social">
2544
{% for social in config.extra.social %}
@@ -33,8 +52,8 @@
3352
<!-- Compute title and render link -->
3453
{% set title = social.name %}
3554
{% if not title and "//" in social.link %}
36-
{% set (_, url) = social.link.split("//") %}
37-
{% set title = url.split("/") | first %}
55+
{% set url = split_and_get(social.link, "//", 1) %}
56+
{% set title = split_and_get(url, "/", 0) %}
3857
{% endif %}
3958
<a
4059
href="{{ social.link }}"

0 commit comments

Comments
 (0)