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 libs %}{% endblock %}
{% block fonts %} {% block fonts %}
{% if config.theme.font != false %} {% 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="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family={{ <link rel="stylesheet" href="https://fonts.googleapis.com/css?family={{
font.text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' + text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
font.code | replace(' ', '+') + ':400,400i,700,700i' code | replace(' ', '+') + ':400,400i,700,700i'
}}&display=fallback"> }}&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 %} {% endif %}
{% endblock %} {% endblock %}
{% for path in config["extra_css"] %} {% for path in config["extra_css"] %}

View File

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