From 8d51b8ba619af4504ad40386f6b452e50ec8a39b Mon Sep 17 00:00:00 2001
From: Christian Bromann <github@christian-bromann.com>
Date: Wed, 29 Sep 2021 11:19:47 +0000
Subject: [PATCH] feat: Added support for Google Fonts (#255)
---
layouts/partials/head.html | 9 +++++++++
exampleSite/config/_default/params.toml | 2 ++
README.md | 13 +++++++++++++
3 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 18dfa72..34499c3 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@
- Open Graph support
- MIT License
- Fontawesome 5.15.1 icons
+- Google Fonts support
- Custom CSS (optional)
- Custom JavaScript (optional)
- Medium like zoom for images
@@ -368,6 +369,18 @@
Replace the hash with the one Google provided you.
+### Google Fonts
+
+You can enable any [Google Font](https://fonts.google.com/) by selecting a font on the Google Font website and adding the `family` parameter of the font url to the `googleFonts` option in `[params]`, e.g.:
+
+```toml
+[params]
+googleFonts = [
+ "Indie+Flower",
+ "Roboto:ital,wght@0,100;0,400;0,700;1,400"
+]
+```
+
### Beautiful math functions
```toml
diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml
index e6faf08..b45c45f 100644
--- a/exampleSite/config/_default/params.toml
+++ b/exampleSite/config/_default/params.toml
@@ -15,6 +15,8 @@
doNotLoadAnimations = false
# Form Spree Contact Form
#contactFormAction = "https://formspree.io/f/your-form-hash-here"
+# Google Fonts
+#googleFonts = ["Indie+Flower", "Roboto:ital,wght@0,100;0,400;0,700;1,400"]
# Google Site Verify
#googleSiteVerify = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
singleDateFormat = "2/1/2006"
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 042003d..f4c9ef6 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -99,6 +99,15 @@
/>
{{- end -}}
+ {{ if .Site.Params.googleFonts }}
+ {{ $baseUrl := "https://fonts.googleapis.com/css2?family=" }}
+ {{ $fontParam := delimit .Site.Params.googleFonts "&family=" }}
+ {{ $url := printf "%s" "&display=swap" | printf "%s%s" $fontParam | printf "%s%s" $baseUrl | printf "%s" }}
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="{{ $url }}" rel="stylesheet">
+
+ {{- end -}}
<!-- Favicons -->
--
Gitblit v1.10.0