]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/tplimpl: Fix allowFullScreen option in Vimeo and YouTube shortcodes
authorJoe Mooring <joe@mooring.com>
Thu, 24 Apr 2025 21:14:46 +0000 (14:14 -0700)
committerGitHub <noreply@github.com>
Thu, 24 Apr 2025 21:14:46 +0000 (14:14 -0700)
Closes #13650

tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
tpl/tplimpl/shortcodes_integration_test.go

index 3ce470c6e6d8aa0e12755785b506f0affa69e245..2588ac86cc186b00d14205d06ec89277a7a45d39 100644 (file)
@@ -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 := "" }}
index cebe50626cad93ca76b9d1797092a7c9f4c2ecc7..18b0869445f877d512c263369fc60a003daa327f 100644 (file)
@@ -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 }}
index 9c541a1e2180f824809f998b56aa3d0c4e41ded7..9d7af4a3da88edfda6ad4975412d0da1dea470cf 100644 (file)
@@ -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")
 }