Fixed malformed Google Fonts url when a font setting was omitted

This commit is contained in:
squidfunk 2022-03-01 07:49:57 +01:00
parent 791c69af7b
commit 64e5ed0ed7
2 changed files with 11 additions and 9 deletions

View File

@ -50,13 +50,14 @@
{% block libs %}{% endblock %}
{% block fonts %}
{% if config.theme.font != false %}
{% set font = config.theme.font %}
{% set text = config.theme.font.text | d("Roboto", true) %}
{% set code = config.theme.font.code | d("Roboto Mono", true) %}
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family={{
font.text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
font.code | replace(' ', '+') + ':400,400i,700,700i'
text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
code | replace(' ', '+') + ':400,400i,700,700i'
}}&display=fallback">
<style>:root{--md-text-font:"{{ font.text }}";--md-code-font:"{{ font.code }}"}</style>
<style>:root{--md-text-font:"{{ text }}";--md-code-font:"{{ code }}"}</style>
{% endif %}
{% endblock %}
{% for path in config["extra_css"] %}

View File

@ -102,19 +102,20 @@
<!-- Load fonts from Google -->
{% if config.theme.font != false %}
{% set font = config.theme.font %}
{% set text = config.theme.font.text | d("Roboto", true) %}
{% set code = config.theme.font.code | d("Roboto Mono", true) %}
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family={{
font.text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
font.code | replace(' ', '+') + ':400,400i,700,700i'
text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
code | replace(' ', '+') + ':400,400i,700,700i'
}}&display=fallback"
/>
<style>
:root {
--md-text-font: "{{ font.text }}";
--md-code-font: "{{ font.code }}";
--md-text-font: "{{ text }}";
--md-code-font: "{{ code }}";
}
</style>
{% endif %}