From 398ca6e2f300cce5c7bf7fa69fde42b4b592f5a4 Mon Sep 17 00:00:00 2001
From: Jiawei Huang
Date: Sun, 14 Jun 2020 14:05:14 -0700
Subject: Add preliminary Google AdSense support

When `googleAdsense` is set in `config.toml`, the AdSense code snippet
will be inserted between the `<head></head>` tags of your site. Only
Google AdSense Auto ads is supported at the moment.
---
 README.md                  | 2 +-
 exampleSite/config.toml    | 4 ++++
 layouts/partials/head.html | 9 +++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d8f4428..0ca6fd5 100644
--- a/README.md
+++ b/README.md
@@ -68,7 +68,7 @@ Inside the folder of your Hugo site run:
 $ git submodule update --remote --merge
 ```
 
-## ⚙️ Configration
+## ⚙️ Configuration
 
 ### 🎨 Favicon
 
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index 72e22b7..4ba95b6 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -29,6 +29,10 @@ paginate = 10
   # googleAnalyticsTid = "UA-000000000-0"
   # googleAnalyticsRoute = "https://*.*.workers.dev/"
 
+  # Google AdSense
+  # The AdSense code will be inserted between the head tags of your site.
+  # googleAdsense = "0000000000000000"
+
   # Word counter and read time indicator in post metadata
   showWordCounter = true
   showReadTime = false
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 0603c4d..b953cd8 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -41,6 +41,15 @@
 <link rel="stylesheet" href="{{ "/assets/css/fuji.min.css" | relURL }}" />
 {{ end }}
 
+{{ if .Site.Params.googleAdsense }}
+<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
+<script>
+  (adsbygoogle = window.adsbygoogle || []).push({
+    enable_page_level_ads: true,
+    google_ad_client: "ca-pub-{{.Site.Params.googleAdsense}}",
+  });
+</script>
+{{ end}}
 {{ if .Params.playerURL }}
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css" />
 {{ end }}
-- 
cgit v1.2.3