Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug when theme.font has empty family value #1015

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions layout/_partials/head/external-fonts.swig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% set font_display = '&display=swap' %}
{% set font_subset = '&subset=latin,latin-ext' %}
{% set font_styles = ':300,300italic,400,400italic,700,700italic' %}
{% set font_host = font_config.host | default('//fonts.googleapis.com') %}

{% if font_config.global.family and font_config.global.external %}
{% set font_global = font_config.global.family + font_styles %}
Expand All @@ -27,11 +28,31 @@
{% set font_codes = font_config.codes.family + font_styles %}
{% endif %}

{# Get a font list from font_config #}
{% set font_families = [font_global, font_title, font_headings, font_posts, font_codes] %}

{# Original font list is not empty #}
{% if font_families !== '' %}
{% set font_host = font_config.host | default('//fonts.googleapis.com') %}
<link rel="stylesheet" href="{{ font_host }}/css?family={{ String(font_families | uniq | join('|')).slice(0, -1).concat(font_display, font_subset) }}"/>
{# Original font list includes empty value - Some font is not setted. #}
{% if font_families.includes('') %}
{# Unique filter original font list and join `/`, then convert it to font string #}
{% set font_families = String(font_families | uniq | join('|')) %}
{# Font string ends with `|` - The last font is not setted #}
{% if font_families.endsWith('|') %}
{# Remove the unneeded last `|` from font string #}
{% set font_families = font_families.slice(0, -1) %}
{# Font string contains `||` - The font in middle part is not fully setted. #}
{% else %}
{# Replace the unneeded `||` in font string with `|` #}
{% set font_families = font_families.replace('||', '|') %}
{% endif %}
{# Original font list doesn't include empty value - Every font is setted. #}
{% else %}
{# Unique filter original font list and join `/`, then convert it to font string #}
{% set font_families = String(font_families | uniq | join('|')) %}
{% endif %}
{# Merge extra parameters to the final processed font string #}
{##}<link rel="stylesheet" href="{{ font_host }}/css?family={{ font_families.concat(font_display, font_subset) }}"/>
{% endif %}

{% endif %}