From 88e356868062cc618385cd22b6730df2459518cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 21 May 2018 17:34:21 +0200 Subject: Add YouTube shortcode simple mode Adapted from the work of @onedrawingperday. See #4616 --- config/privacy/privacyConfig.go | 7 ++- tpl/tplimpl/embedded/templates.autogen.go | 66 +++++++++++++++++++--- .../templates/shortcodes/__h_simple_assets.html | 34 +++++++++++ .../embedded/templates/shortcodes/youtube.html | 18 +++--- .../templates/shortcodes/youtube_simple.html | 13 +++++ 5 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 tpl/tplimpl/embedded/templates/shortcodes/__h_simple_assets.html create mode 100644 tpl/tplimpl/embedded/templates/shortcodes/youtube_simple.html diff --git a/config/privacy/privacyConfig.go b/config/privacy/privacyConfig.go index 64bbe71bb..4da7efbea 100644 --- a/config/privacy/privacyConfig.go +++ b/config/privacy/privacyConfig.go @@ -76,8 +76,13 @@ type YouTube struct { // When you turn on privacy-enhanced mode, // YouTube won’t store information about visitors on your website - // unless they play the video. + // unless the user plays the embedded video. PrivacyEnhanced bool + + // If simple mode is enabled, only a thumbnail is fetched from ytimg.com and + // shown with a play button overlaid. If a user clicks the button, he/she will + // be taken to the video page on youtube.com in a new browser tab. + Simple bool } func DecodeConfig(cfg config.Provider) (pc Config, err error) { diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 7ba6a3043..865859b49 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -241,6 +241,41 @@ if (!doNotTrack) { {{ end }}`}, + {`shortcodes/__h_simple_assets.html`, `{{ define "__h_simple_css" }}{{/* This is also used in other "simple" variants. These template definitions are global. */}} +{{ if not (.Page.Scratch.Get "__h_simple_css") }} +{{/* Only include once */}} +{{ .Page.Scratch.Set "__h_simple_css" true }} + +{{ end }} +{{ end }} + +{{- define "__h_simple_icon_play" -}} +M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z +{{- end -}} +`}, {`shortcodes/figure.html`, ` {{ if .Get "link"}}{{ end }} @@ -287,17 +322,30 @@ if (!doNotTrack) { {{- end -}}`}, {`shortcodes/youtube.html`, `{{- $pc := .Page.Site.PrivacyConfig.YouTube -}} {{- if not $pc.Disable -}} -{{ $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }} -{{ if .IsNamedParams }} -
- -
{{ else }} -
- -
+{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} +{{- if $pc.Simple -}} +{{ template "_internal/shortcodes/youtube_simple.html" . }} +{{- else -}} +{{- $id := .Get "id" | default (.Get 0) -}} +{{- $class := .Get "class" | default (.Get 1) }} +
+ +
{{ end }} {{- end -}}`}, + {`shortcodes/youtube_simple.html`, `{{ $id := .Get "id" | default (.Get 0) }} +{{ $class := .Get "class" | default (.Get 1) }} +{{ $hasClass := $class }} +{{ $class := $class | default "__h_youtube" }} +{{ if not $hasClass }} +{{/* If class is set, assume the user wants to provide his own styles. */}} +{{ template "__h_simple_css" $ }} +{{ end }} +
`}, {`twitter_cards.html`, `{{- with $.Params.images -}} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/__h_simple_assets.html b/tpl/tplimpl/embedded/templates/shortcodes/__h_simple_assets.html new file mode 100644 index 000000000..837378329 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/__h_simple_assets.html @@ -0,0 +1,34 @@ +{{ define "__h_simple_css" }}{{/* This is also used in other "simple" variants. These template definitions are global. */}} +{{ if not (.Page.Scratch.Get "__h_simple_css") }} +{{/* Only include once */}} +{{ .Page.Scratch.Set "__h_simple_css" true }} + +{{ end }} +{{ end }} + +{{- define "__h_simple_icon_play" -}} +M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z +{{- end -}} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html index 3a3ff4241..b0da600a3 100755 --- a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html @@ -1,13 +1,13 @@ {{- $pc := .Page.Site.PrivacyConfig.YouTube -}} {{- if not $pc.Disable -}} -{{ $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }} -{{ if .IsNamedParams }} -
- -
{{ else }} -
- -
+{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} +{{- if $pc.Simple -}} +{{ template "_internal/shortcodes/youtube_simple.html" . }} +{{- else -}} +{{- $id := .Get "id" | default (.Get 0) -}} +{{- $class := .Get "class" | default (.Get 1) }} +
+ +
{{ end }} {{- end -}} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/youtube_simple.html b/tpl/tplimpl/embedded/templates/shortcodes/youtube_simple.html new file mode 100644 index 000000000..15c684619 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/youtube_simple.html @@ -0,0 +1,13 @@ +{{ $id := .Get "id" | default (.Get 0) }} +{{ $class := .Get "class" | default (.Get 1) }} +{{ $hasClass := $class }} +{{ $class := $class | default "__h_youtube" }} +{{ if not $hasClass }} +{{/* If class is set, assume the user wants to provide his own styles. */}} +{{ template "__h_simple_css" $ }} +{{ end }} +
+{{ $tb := printf "https://i.ytimg.com/vi/%s/" $id }} + + Video +
\ No newline at end of file -- cgit v1.2.3