From cd023168da9c5ef055daa9e837d686f257df2d8a Mon Sep 17 00:00:00 2001 From: Jacques Supcik Date: Thu, 2 Jul 2020 00:30:04 +0200 Subject: [PATCH] feat: add support for Google Fonts API v2 See #1767 Close #1714 --- layouts/partials/site_head.html | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/layouts/partials/site_head.html b/layouts/partials/site_head.html index 3de927fc..f2467e5e 100644 --- a/layouts/partials/site_head.html +++ b/layouts/partials/site_head.html @@ -114,10 +114,17 @@ {{ end }} - {{/* We cannot use SRI with Google Fonts because the CSS is dynamically generated according to the user agent. */}} - {{/* Hugo's htmlEscape cannot escape "|" in Google Font URIs so we implement our own escape functionality. */}} + {{/* Load Google Fonts if the site's Font Theme uses them. */}} + {{/* Note: we cannot use SRI with Google Fonts because the CSS is dynamically generated according to the user agent. */}} {{ with ($scr.Get "google_fonts") }} - + {{ if hasPrefix . "family=" }} + {{/* If `google_fonts` starts with "family=", use API v2 (https://developers.google.com/fonts/docs/css2) */}} + + {{ else }} + {{/* Otherwise, use API v1 */}} + {{/* Hugo's htmlEscape cannot escape "|" in Google Font URIs so we implement our own escape functionality. */}} + + {{ end }} {{ end }} {{ $css_comment := printf "/*!* Source Themes Academic v%s (https://sourcethemes.com/academic/) */\n" site.Data.academic.version }}