mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-27 05:18:28 -04:00
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
This commit is contained in:
parent
3e8d20eb61
commit
be6f8b1fef
@ -5,11 +5,13 @@
|
||||
{{ hugo.Generator }}
|
||||
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
||||
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
|
||||
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
|
||||
<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>
|
||||
<script async custom-element="amp-twitter" src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js"></script>
|
||||
<script async custom-element="amp-facebook" src="https://cdn.ampproject.org/v0/amp-facebook-0.1.js"></script>
|
||||
<script async custom-element="amp-gist" src="https://cdn.ampproject.org/v0/amp-gist-0.1.js"></script>
|
||||
{{ if .HasShortcode "video" }}<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "youtube" }}<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "tweet" }}<script async custom-element="amp-twitter" src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "facebook" }}<script async custom-element="amp-facebook" src="https://cdn.ampproject.org/v0/amp-facebook-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "gist" }}<script async custom-element="amp-gist" src="https://cdn.ampproject.org/v0/amp-gist-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "instagram" }}<script async custom-element="amp-gist" src="https://cdn.ampproject.org/v0/amp-instagram-0.1.js"></script>{{ end }}
|
||||
{{ if .HasShortcode "vimeo" }}<script async custom-element="amp-gist" src="https://cdn.ampproject.org/v0/amp-vimeo-0.1.js"></script>{{ end }}
|
||||
<title>{{ .Title }} – {{ .Site.Title }}</title>
|
||||
{{ with .OutputFormats.Get "html" }}<link rel="canonical" href="{{ .Permalink }}">{{ end }}
|
||||
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
|
||||
@ -169,6 +171,7 @@
|
||||
<link rel="icon" href="{{ "favicon-32.png" | absURL }}" sizes="32x32">
|
||||
<link rel="icon" href="{{ "favicon-16.png" | absURL }}" sizes="16x16">
|
||||
<link rel="shortcut icon" href="{{ "favicon.ico" | absURL }}">
|
||||
<link rel="manifest" href="{{ "site.webmanifest" | absURL }}">
|
||||
<link rel="alternate" type="application/rss+xml" href="{{ "feed.xml" | absURL }}" title="{{ .Site.Title }} (RSS)">
|
||||
|
||||
{{ partial "head/schema-person" . }}
|
||||
|
@ -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 -}}
|
||||
|
@ -1,2 +0,0 @@
|
||||
<div id="fb-root"></div>
|
||||
<script async defer src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v5.0"></script>
|
@ -1 +0,0 @@
|
||||
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
@ -1 +0,0 @@
|
||||
<script async defer src="https://platform.twitter.com/widgets.js"></script>
|
@ -4,3 +4,8 @@
|
||||
<div class="embed facebook">
|
||||
{{ $json.html | safeHTML }}
|
||||
</div>
|
||||
|
||||
{{- define "__shortcode_facebook_js" }}
|
||||
<div id="fb-root"></div>
|
||||
<script async defer src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v5.0"></script>
|
||||
{{- end }}
|
||||
|
@ -2,3 +2,7 @@
|
||||
<a class="github-button" href="https://github.com/{{ .Get "username" }}/{{ .Get "repo" }}" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star {{ .Get "username" }}/{{ .Get "repo" }} on GitHub">Star</a>
|
||||
<a class="github-button" href="https://github.com/{{ .Get "username" }}/{{ .Get "repo" }}/issues" data-icon="octicon-issue-opened" data-size="large" data-show-count="true" aria-label="Issues for {{ .Get "username" }}/{{ .Get "repo" }} on GitHub">Issue</a>
|
||||
</p></div>
|
||||
|
||||
{{- define "__shortcode_gh-buttons_js" }}
|
||||
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
||||
{{- end }}
|
||||
|
7
layouts/shortcodes/instagram.amp.html
Normal file
7
layouts/shortcodes/instagram.amp.html
Normal file
@ -0,0 +1,7 @@
|
||||
<amp-instagram
|
||||
data-shortcode="{{ .Get "id" }}"
|
||||
data-captioned
|
||||
width="500"
|
||||
height="500"
|
||||
layout="responsive">
|
||||
</amp-instagram>
|
10
layouts/shortcodes/instagram.html
Normal file
10
layouts/shortcodes/instagram.html
Normal file
@ -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 -}}
|
||||
|
||||
<div class="embed instagram">
|
||||
{{ $json.html | safeHTML }}
|
||||
</div>
|
||||
|
||||
{{- define "__shortcode_instagram_js" }}
|
||||
<script async src="https://www.instagram.com/embed.js"></script>
|
||||
{{- end }}
|
1
layouts/shortcodes/instagram.rss.xml
Normal file
1
layouts/shortcodes/instagram.rss.xml
Normal file
@ -0,0 +1 @@
|
||||
<p style="text-align: center;"><a href="https://www.instagram.com/p/{{ .Get "id" }}" target="_blank" rel="noopener">View this image on Instagram.</a></p>
|
@ -4,3 +4,7 @@
|
||||
<div class="embed tweet">
|
||||
{{ $json.html | safeHTML }}
|
||||
</div>
|
||||
|
||||
{{- define "__shortcode_twitter_js" }}
|
||||
<script async defer src="https://platform.twitter.com/widgets.js"></script>
|
||||
{{- end }}
|
||||
|
6
layouts/shortcodes/vimeo.amp.html
Normal file
6
layouts/shortcodes/vimeo.amp.html
Normal file
@ -0,0 +1,6 @@
|
||||
<amp-vimeo
|
||||
data-videoid="{{ .Get "id" }}"
|
||||
layout="responsive"
|
||||
width="500"
|
||||
height="281">
|
||||
</amp-vimeo>
|
7
layouts/shortcodes/vimeo.html
Normal file
7
layouts/shortcodes/vimeo.html
Normal file
@ -0,0 +1,7 @@
|
||||
<div class="embed vimeo" style="padding:75% 0 0 0;position:relative;">
|
||||
<iframe src="https://player.vimeo.com/video/{{ .Get "id" }}&dnt=1" style="position:absolute;top:0;left:0;width:100%;height:100%;" frameborder="0" allow="fullscreen" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
{{- define "__shortcode_vimeo_js" }}
|
||||
<script src="https://player.vimeo.com/api/player.js"></script>
|
||||
{{ end }}
|
1
layouts/shortcodes/vimeo.rss.xml
Normal file
1
layouts/shortcodes/vimeo.rss.xml
Normal file
@ -0,0 +1 @@
|
||||
<p style="text-align: center;"><a href="https://vimeo.com/{{ .Get "id" }}" target="_blank" rel="noopener">Watch this video on Vimeo.</a></p>
|
@ -1 +1 @@
|
||||
<p style="text-align: center;"><a href="https://www.youtube.com/watch?v={{ index .Params 0 }}">Watch this video on YouTube.</a></p>
|
||||
<p style="text-align: center;"><a href="https://www.youtube.com/watch?v={{ index .Params 0 }}" target="_blank" rel="noopener">Watch this video on YouTube.</a></p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user