Repository: gohugoio/hugo (language: go)

Issue:
Youtube shortcode now disables fullscreen by default
The changes introduced to the `youtube` shortcode via

- #13532 

toggled the default for `fullscreen` from true (up until v0.145.x) to false in the latest release.

If you build the attached minimal sample project this is the diff (over the prettified) HTML output of a page using the shortcode:

```diff
5c5
<   <meta name="generator" content="Hugo 0.145.0">
---
>   <meta name="generator" content="Hugo 0.146.7">
14d13
<         allowfullscreen="allowfullscreen"
```

Notice that the `allowfullscreen` attribute is gone in v0.146. We should be seeing the addition of `allow="fullscreen; ..."`. Can we recover the old default?

📎 Test project: [hugo-youtube-demo.zip](https://github.com/user-attachments/files/19894972/hugo-youtube-demo.zip) (updated)


Discussion / hints:

Fix patch:
diff --git a/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html b/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
index 3ce470c6e6d..2588ac86cc1 100644
--- a/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
+++ b/tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html
@@ -4,11 +4,11 @@
 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 @@
   {{- 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 cebe50626ca..18b0869445f 100644
--- a/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
+++ b/tpl/tplimpl/embedded/templates/_shortcodes/youtube.html
@@ -6,7 +6,7 @@
 @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 @@
 
     {{- /* 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 @@
     {{- $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 }}


Test patch:
diff --git a/tpl/tplimpl/shortcodes_integration_test.go b/tpl/tplimpl/shortcodes_integration_test.go
index 9c541a1e218..9d7af4a3da8 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")
 }