summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Mooring <joe@mooring.com>2025-04-24 14:14:46 -0700
committerGitHub <noreply@github.com>2025-04-24 14:14:46 -0700
commit5c491409d36d31f77cdc0407ed29ae2dca71363b (patch)
treee945d2db0fef021da458ffbb727592c20e5f7f63
parent75b219db896cd0ae962f062b39fd67c38dfc8e5b (diff)
downloadhugo-5c491409d36d31f77cdc0407ed29ae2dca71363b.tar.gz
hugo-5c491409d36d31f77cdc0407ed29ae2dca71363b.zip
tpl/tplimpl: Fix allowFullScreen option in Vimeo and YouTube shortcodes
Closes #13650
-rw-r--r--tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html20
-rw-r--r--tpl/tplimpl/embedded/templates/_shortcodes/youtube.html35
-rw-r--r--tpl/tplimpl/shortcodes_integration_test.go10
3 files changed, 36 insertions, 29 deletions
diff --git a/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html b/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
index 3ce470c6e..2588ac86c 100644
--- a/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
+++ b/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
@@ -4,11 +4,11 @@ Renders an embedded Vimeo video.
Accepts named or positional arguments. If positional, order is id, class,
title, then loading.
-@param {string} [id] The video id. Optional if the id is provided as first positional argument.
+@param {bool} [allowFullScreen=true] Whether the iframe element can activate full screen mode.
@param {string} [class] The class attribute of the wrapping div element. When specified, removes the style attributes from the iframe element and its wrapping div element.
+@param {string} [id] The video id. Optional if the id is the first and only positional argument.
@param {string} [loading=eager] The loading attribute of the iframe element.
@param {string} [title=Vimeo video] The title attribute of the iframe element.
-@param {bool} [allowFullScreen=true] Whether the iframe element can activate full screen mode.
@returns {template.HTML}
@@ -22,16 +22,16 @@ title, then loading.
{{- else }}
{{- $dnt := cond $pc.EnableDNT 1 0 }}
- {{- $id := or (.Get "id") (.Get 0) "" }}
- {{- $class := or (.Get "class") (.Get 1) "" }}
- {{- $title := or (.Get "title") (.Get 2) "Vimeo video" }}
- {{- $loading := or (.Get "loading") (.Get 3) "eager" }}
- {{- $allowFullScreen := or (.Get "allowFullScreen") (.Get 4) true }}
+ {{- $allowFullScreen := true }}
+ {{- $class := or (.Get "class") }}
+ {{- $id := or (.Get "id") (.Get 0) }}
+ {{- $loading := or (.Get "loading") }}
+ {{- $title := or (.Get "title") }}
- {{- if in (slice "false" false 0) ($.Get "allowFullScreen") }}
- {{- $allowFullScreen = false }}
- {{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
+ {{- if in (slice "true" true 1) (.Get "allowFullScreen") }}
{{- $allowFullScreen = true }}
+ {{- else if in (slice "false" false 0) (.Get "allowFullScreen") }}
+ {{- $allowFullScreen = false }}
{{- end }}
{{- $iframeAllowList := "" }}
diff --git a/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html b/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
index cebe50626..18b086944 100644
--- a/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
+++ b/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
@@ -6,7 +6,7 @@ Renders an embedded YouTube video.
@param {string} [class] The class attribute of the wrapping div element. When specified, removes the style attributes from the iframe element and its wrapping div element.
@param {bool} [controls=true] Whether to display the video controls.
@param {int} [end] The time, measured in seconds from the start of the video, when the player should stop playing the video.
-@param {string} [id] The video id. Optional if the id is provided as first positional argument.
+@param {string} [id] The video id. Optional if the id is the first and only positional argument.
@param {string} [loading=eager] The loading attribute of the iframe element.
@param {bool} [loop=false] Whether to indefinitely repeat the video. Ignores the start and end arguments after the first play.
@param {bool} [mute=false] Whether to mute the video. Always true when autoplay is true.
@@ -41,27 +41,29 @@ Renders an embedded YouTube video.
{{- /* Get arguments. */}}
{{- if in (slice "true" true 1) ($.Get "allowFullScreen") }}
- {{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
+ {{- $allowFullScreen = true }}
+ {{- else if in (slice "false" false 0) ($.Get "allowFullScreen") }}
+ {{- $allowFullScreen = false }}
{{- end }}
- {{- if in (slice "false" false 0) ($.Get "autoplay") }}
- {{- $autoplay = 0 }}
- {{- else if in (slice "true" true 1) ($.Get "autoplay") }}
+ {{- if in (slice "true" true 1) ($.Get "autoplay") }}
{{- $autoplay = 1 }}
+ {{- else if in (slice "false" false 0) ($.Get "autoplay") }}
+ {{- $autoplay = 0 }}
{{- end }}
- {{- if in (slice "false" false 0) ($.Get "controls") }}
- {{- $controls = 0 }}
- {{- else if in (slice "true" true 1) ($.Get "controls") }}
+ {{- if in (slice "true" true 1) ($.Get "controls") }}
{{- $controls = 1 }}
+ {{- else if in (slice "false" false 0) ($.Get "controls") }}
+ {{- $controls = 0 }}
{{- end }}
- {{- if in (slice "false" false 0) ($.Get "loop") }}
- {{- $loop = 0 }}
- {{- else if in (slice "true" true 1) ($.Get "loop") }}
+ {{- if in (slice "true" true 1) ($.Get "loop") }}
{{- $loop = 1 }}
+ {{- else if in (slice "false" false 0) ($.Get "loop") }}
+ {{- $loop = 0 }}
{{- end }}
- {{- if in (slice "false" false 0) ($.Get "mute") }}
- {{- $mute = 0 }}
- {{- else if or (in (slice "true" true 1) ($.Get "mute")) $autoplay }}
+ {{- if or (in (slice "true" true 1) ($.Get "mute")) $autoplay }}
{{- $mute = 1 }}
+ {{- else if in (slice "false" false 0) ($.Get "mute") }}
+ {{- $mute = 0 }}
{{- end }}
{{- $class := or ($.Get "class") $class }}
{{- $end := or ($.Get "end") $end }}
@@ -69,6 +71,11 @@ Renders an embedded YouTube video.
{{- $start := or ($.Get "start") $start }}
{{- $title := or ($.Get "title") $title }}
+ {{- /* Adjust iframeAllowList. */}}
+ {{- if $allowFullScreen }}
+ {{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
+ {{- end }}
+
{{- /* Define src attribute. */}}
{{- $host := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }}
{{- $src := printf "https://%s/embed/%s" $host $id }}
diff --git a/tpl/tplimpl/shortcodes_integration_test.go b/tpl/tplimpl/shortcodes_integration_test.go
index 9c541a1e2..9d7af4a3d 100644
--- a/tpl/tplimpl/shortcodes_integration_test.go
+++ b/tpl/tplimpl/shortcodes_integration_test.go
@@ -488,9 +488,9 @@ Content: {{ .Content }}
// Regular mode
b := hugolib.Test(t, files)
- b.AssertFileContent("public/p1/index.html", "f7687b0c4e85b7d4")
- b.AssertFileContent("public/p2/index.html", "f7687b0c4e85b7d4")
- b.AssertFileContent("public/p3/index.html", "caca499bdc7f1e1e")
+ b.AssertFileContent("public/p1/index.html", "82566e6b8d04b53e")
+ b.AssertFileContent("public/p2/index.html", "82566e6b8d04b53e")
+ b.AssertFileContent("public/p3/index.html", "2b5f9cc3167d1336")
// Simple mode
files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true")
@@ -687,12 +687,12 @@ title: p2
b := hugolib.Test(t, files)
- b.AssertFileContent("public/p1/index.html", "5156322adda11844")
+ b.AssertFileContent("public/p1/index.html", "4b54bf9bd03946ec")
b.AssertFileContent("public/p2/index.html", "289c655e727e596c")
files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true")
b = hugolib.Test(t, files)
- b.AssertFileContent("public/p1/index.html", "599174706edf963a")
+ b.AssertFileContent("public/p1/index.html", "78eb19b5c6f3768f")
b.AssertFileContent("public/p2/index.html", "a6db910a9cf54bc1")
}