From be6f8b1fef10aecefbb5d4947a546511c4d79556 Mon Sep 17 00:00:00 2001
From: Jake Jarvis
Date: Mon, 20 Jan 2020 11:32:40 -0500
Subject: [PATCH] simplify shortcode JS logic and only call AMP script if
shortcodes present
fixes https://search.google.com/search-console/amp/drilldown?resource_id=sc-domain%3Ajarv.is&item_key=GgcIIhADKKZO&utm_source=wnc_10030322&utm_medium=gamma&utm_campaign=wnc_10030322&utm_content=msg_100058679&hl=en&sharing_key=VVX9zj1yTzUxHPzmKFP4Gg
---
layouts/_default/single.amp.html | 13 ++++++++-----
layouts/partials/scripts/shortcodes.html | 14 +++++++++++---
layouts/partials/scripts/shortcodes/facebook.html | 2 --
.../partials/scripts/shortcodes/gh-buttons.html | 1 -
layouts/partials/scripts/shortcodes/tweet.html | 1 -
layouts/shortcodes/facebook.html | 5 +++++
layouts/shortcodes/gh-buttons.html | 4 ++++
layouts/shortcodes/instagram.amp.html | 7 +++++++
layouts/shortcodes/instagram.html | 10 ++++++++++
layouts/shortcodes/instagram.rss.xml | 1 +
layouts/shortcodes/tweet.html | 4 ++++
layouts/shortcodes/vimeo.amp.html | 6 ++++++
layouts/shortcodes/vimeo.html | 7 +++++++
layouts/shortcodes/vimeo.rss.xml | 1 +
layouts/shortcodes/youtube.rss.xml | 2 +-
15 files changed, 65 insertions(+), 13 deletions(-)
delete mode 100644 layouts/partials/scripts/shortcodes/facebook.html
delete mode 100644 layouts/partials/scripts/shortcodes/gh-buttons.html
delete mode 100644 layouts/partials/scripts/shortcodes/tweet.html
create mode 100644 layouts/shortcodes/instagram.amp.html
create mode 100644 layouts/shortcodes/instagram.html
create mode 100644 layouts/shortcodes/instagram.rss.xml
create mode 100644 layouts/shortcodes/vimeo.amp.html
create mode 100644 layouts/shortcodes/vimeo.html
create mode 100644 layouts/shortcodes/vimeo.rss.xml
diff --git a/layouts/_default/single.amp.html b/layouts/_default/single.amp.html
index 43319e32..d256a94f 100644
--- a/layouts/_default/single.amp.html
+++ b/layouts/_default/single.amp.html
@@ -5,11 +5,13 @@
{{ hugo.Generator }}
-
-
-
-
-
+ {{ if .HasShortcode "video" }}{{ end }}
+ {{ if .HasShortcode "youtube" }}{{ end }}
+ {{ if .HasShortcode "tweet" }}{{ end }}
+ {{ if .HasShortcode "facebook" }}{{ end }}
+ {{ if .HasShortcode "gist" }}{{ end }}
+ {{ if .HasShortcode "instagram" }}{{ end }}
+ {{ if .HasShortcode "vimeo" }}{{ end }}
{{ .Title }} – {{ .Site.Title }}
{{ with .OutputFormats.Get "html" }}{{ end }}
@@ -169,6 +171,7 @@
+
{{ partial "head/schema-person" . }}
diff --git a/layouts/partials/scripts/shortcodes.html b/layouts/partials/scripts/shortcodes.html
index a0a3917c..a3284d49 100644
--- a/layouts/partials/scripts/shortcodes.html
+++ b/layouts/partials/scripts/shortcodes.html
@@ -1,11 +1,19 @@
{{ if .HasShortcode "gh-buttons" -}}
-{{ partial "scripts/shortcodes/gh-buttons" . }}
+{{ template "__shortcode_gh-buttons_js" $ }}
{{ end -}}
{{ if .HasShortcode "tweet" -}}
-{{ partial "scripts/shortcodes/tweet" . }}
+{{ template "__shortcode_twitter_js" $ }}
{{ end -}}
{{ if .HasShortcode "facebook" -}}
-{{ partial "scripts/shortcodes/facebook" . }}
+{{ template "__shortcode_facebook_js" $ }}
+{{ end -}}
+
+{{ if .HasShortcode "instagram" -}}
+{{ template "__shortcode_instagram_js" $ }}
+{{ end -}}
+
+{{ if .HasShortcode "vimeo" -}}
+{{ template "__shortcode_vimeo_js" $ }}
{{ end -}}
diff --git a/layouts/partials/scripts/shortcodes/facebook.html b/layouts/partials/scripts/shortcodes/facebook.html
deleted file mode 100644
index 78c63842..00000000
--- a/layouts/partials/scripts/shortcodes/facebook.html
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/layouts/partials/scripts/shortcodes/gh-buttons.html b/layouts/partials/scripts/shortcodes/gh-buttons.html
deleted file mode 100644
index 668938fc..00000000
--- a/layouts/partials/scripts/shortcodes/gh-buttons.html
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/layouts/partials/scripts/shortcodes/tweet.html b/layouts/partials/scripts/shortcodes/tweet.html
deleted file mode 100644
index dc2415ba..00000000
--- a/layouts/partials/scripts/shortcodes/tweet.html
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/layouts/shortcodes/facebook.html b/layouts/shortcodes/facebook.html
index 9499f59d..24b34635 100644
--- a/layouts/shortcodes/facebook.html
+++ b/layouts/shortcodes/facebook.html
@@ -4,3 +4,8 @@
{{ $json.html | safeHTML }}
+
+{{- define "__shortcode_facebook_js" }}
+
+
+{{- end }}
diff --git a/layouts/shortcodes/gh-buttons.html b/layouts/shortcodes/gh-buttons.html
index c6c35065..21dfc260 100644
--- a/layouts/shortcodes/gh-buttons.html
+++ b/layouts/shortcodes/gh-buttons.html
@@ -2,3 +2,7 @@
Star
Issue
+
+{{- define "__shortcode_gh-buttons_js" }}
+
+{{- end }}
diff --git a/layouts/shortcodes/instagram.amp.html b/layouts/shortcodes/instagram.amp.html
new file mode 100644
index 00000000..92c945da
--- /dev/null
+++ b/layouts/shortcodes/instagram.amp.html
@@ -0,0 +1,7 @@
+
+
diff --git a/layouts/shortcodes/instagram.html b/layouts/shortcodes/instagram.html
new file mode 100644
index 00000000..2bc4a29e
--- /dev/null
+++ b/layouts/shortcodes/instagram.html
@@ -0,0 +1,10 @@
+{{- $url := printf "https://api.instagram.com/oembed/?omitscript=1&url=https://www.instagram.com/p/%s" (.Get "id") -}}
+{{- $json := getJSON $url -}}
+
+
+{{ $json.html | safeHTML }}
+
+
+{{- define "__shortcode_instagram_js" }}
+
+{{- end }}
diff --git a/layouts/shortcodes/instagram.rss.xml b/layouts/shortcodes/instagram.rss.xml
new file mode 100644
index 00000000..539b6447
--- /dev/null
+++ b/layouts/shortcodes/instagram.rss.xml
@@ -0,0 +1 @@
+View this image on Instagram.
diff --git a/layouts/shortcodes/tweet.html b/layouts/shortcodes/tweet.html
index babce706..4c3b622c 100644
--- a/layouts/shortcodes/tweet.html
+++ b/layouts/shortcodes/tweet.html
@@ -4,3 +4,7 @@
+
+{{- define "__shortcode_twitter_js" }}
+
+{{- end }}
diff --git a/layouts/shortcodes/vimeo.amp.html b/layouts/shortcodes/vimeo.amp.html
new file mode 100644
index 00000000..f456297f
--- /dev/null
+++ b/layouts/shortcodes/vimeo.amp.html
@@ -0,0 +1,6 @@
+
+
diff --git a/layouts/shortcodes/vimeo.html b/layouts/shortcodes/vimeo.html
new file mode 100644
index 00000000..b8a9a823
--- /dev/null
+++ b/layouts/shortcodes/vimeo.html
@@ -0,0 +1,7 @@
+
+
+
+
+{{- define "__shortcode_vimeo_js" }}
+
+{{ end }}
diff --git a/layouts/shortcodes/vimeo.rss.xml b/layouts/shortcodes/vimeo.rss.xml
new file mode 100644
index 00000000..74ab376f
--- /dev/null
+++ b/layouts/shortcodes/vimeo.rss.xml
@@ -0,0 +1 @@
+Watch this video on Vimeo.
diff --git a/layouts/shortcodes/youtube.rss.xml b/layouts/shortcodes/youtube.rss.xml
index e4292dd0..5c5da0db 100644
--- a/layouts/shortcodes/youtube.rss.xml
+++ b/layouts/shortcodes/youtube.rss.xml
@@ -1 +1 @@
-Watch this video on YouTube.
+Watch this video on YouTube.