tpl/tplimpl: Fix allowFullScreen option in Vimeo and YouTube shortcodes
Some checks are pending
Test / test (1.23.x, ubuntu-latest) (push) Waiting to run
Test / test (1.23.x, windows-latest) (push) Waiting to run
Test / test (1.24.x, ubuntu-latest) (push) Waiting to run
Test / test (1.24.x, windows-latest) (push) Waiting to run

Closes #13650
This commit is contained in:
Joe Mooring 2025-04-24 14:14:46 -07:00 committed by GitHub
parent 75b219db89
commit 5c491409d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 29 deletions

View 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 := "" }}

View 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 }}

View 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")
}