tpl/tplimpl: Fix full screen option in vimeo and youtube shortcodes

Closes #13531

Co-authored-by: Stefan Ritter <60473875+gideonstar-git@users.noreply.github.com>
This commit is contained in:
Joe Mooring
2025-03-26 16:01:01 -07:00
committed by Bjørn Erik Pedersen
parent 8d2379bcb3
commit 6f14dbe24c
3 changed files with 43 additions and 19 deletions

View File

@@ -4,10 +4,11 @@ Renders an embedded Vimeo video.
Accepts named or positional arguments. If positional, order is id, class, Accepts named or positional arguments. If positional, order is id, class,
title, then loading. title, then loading.
@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 provided as first positional argument. @param {string} [id] The video id. Optional if the id is provided as first positional argument.
@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} [loading=eager] The loading attribute of the iframe element. @param {string} [loading=eager] The loading attribute of the iframe element.
@param {string} [title=Vimeo video] The title 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} @returns {template.HTML}
@@ -19,11 +20,24 @@ title, then loading.
{{- if $pc.Simple }} {{- if $pc.Simple }}
{{- template "_internal/shortcodes/vimeo_simple.html" . }} {{- template "_internal/shortcodes/vimeo_simple.html" . }}
{{- else }} {{- else }}
{{- $dnt := cond $pc.EnableDNT 1 0 }}
{{- $id := or (.Get "id") (.Get 0) "" }} {{- $id := or (.Get "id") (.Get 0) "" }}
{{- $class := or (.Get "class") (.Get 1) "" }} {{- $class := or (.Get "class") (.Get 1) "" }}
{{- $title := or (.Get "title") (.Get 2) "Vimeo video" }} {{- $title := or (.Get "title") (.Get 2) "Vimeo video" }}
{{- $loading := or (.Get "loading") (.Get 3) "eager" }} {{- $loading := or (.Get "loading") (.Get 3) "eager" }}
{{- $dnt := cond $pc.EnableDNT 1 0 }} {{- $allowFullScreen := or (.Get "allowFullScreen") (.Get 4) true }}
{{- if in (slice "false" false 0) ($.Get "allowFullScreen") }}
{{- $allowFullScreen = false }}
{{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
{{- $allowFullScreen = true }}
{{- end }}
{{- $iframeAllowList := "" }}
{{- if $allowFullScreen }}
{{- $iframeAllowList = "fullscreen" }}
{{- end }}
{{- $divStyle := "position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;" }} {{- $divStyle := "position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;" }}
{{- $iframeStyle := "position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" }} {{- $iframeStyle := "position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" }}
@@ -36,11 +50,12 @@ title, then loading.
{{- else }} {{- else }}
style="{{ $divStyle | safeCSS }}" style="{{ $divStyle | safeCSS }}"
{{- end }}> {{- end }}>
<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen <iframe
src="{{- $src }}" src="{{- $src }}"
{{- if not $class }} {{- if not $class }}
style="{{ $iframeStyle | safeCSS }}" style="{{ $iframeStyle | safeCSS }}"
{{- end }} {{- end }}
{{- with $iframeAllowList }} allow="{{ . }}" {{- end }}
{{- with $loading }} loading="{{ . }}" {{- end }} {{- with $loading }} loading="{{ . }}" {{- end }}
{{- with $title }} title="{{ . }}" {{- end }}> {{- with $title }} title="{{ . }}" {{- end }}>
</iframe> </iframe>

View File

@@ -27,7 +27,7 @@ Renders an embedded YouTube video.
{{- with $id := or (.Get "id") (.Get 0) }} {{- with $id := or (.Get "id") (.Get 0) }}
{{- /* Set defaults. */}} {{- /* Set defaults. */}}
{{- $allowFullScreen := "allowfullscreen" }} {{- $allowFullScreen := true }}
{{- $autoplay := 0 }} {{- $autoplay := 0 }}
{{- $class := "" }} {{- $class := "" }}
{{- $controls := 1 }} {{- $controls := 1 }}
@@ -37,12 +37,11 @@ Renders an embedded YouTube video.
{{- $mute := 0 }} {{- $mute := 0 }}
{{- $start := 0 }} {{- $start := 0 }}
{{- $title := "YouTube video" }} {{- $title := "YouTube video" }}
{{- $iframeAllowList := "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" }}
{{- /* Get arguments. */}} {{- /* Get arguments. */}}
{{- if in (slice "false" false 0) ($.Get "allowFullScreen") }} {{- if in (slice "true" true 1) ($.Get "allowFullScreen") }}
{{- $allowFullScreen = "" }} {{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
{{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
{{- $allowFullScreen = "allowfullscreen" }}
{{- end }} {{- end }}
{{- if in (slice "false" false 0) ($.Get "autoplay") }} {{- if in (slice "false" false 0) ($.Get "autoplay") }}
{{- $autoplay = 0 }} {{- $autoplay = 0 }}
@@ -99,7 +98,6 @@ Renders an embedded YouTube video.
{{- if $class }} {{- if $class }}
{{- $iframeStyle = "" }} {{- $iframeStyle = "" }}
{{- end }} {{- end }}
{{- $allow := "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" }}
{{- $referrerpolicy := "strict-origin-when-cross-origin" }} {{- $referrerpolicy := "strict-origin-when-cross-origin" }}
{{- /* Render. */ -}} {{- /* Render. */ -}}
@@ -108,8 +106,7 @@ Renders an embedded YouTube video.
{{- with $divStyle }} style="{{ . | safeCSS }}" {{- end -}} {{- with $divStyle }} style="{{ . | safeCSS }}" {{- end -}}
> >
<iframe <iframe
{{- with $allow }} allow="{{ . }}" {{- end }} {{- with $iframeAllowList }} allow="{{ . }}" {{- end }}
{{- with $allowFullScreen }} allowfullscreen="{{ . }}" {{- end }}
{{- with $loading }} loading="{{ . }}" {{- end }} {{- with $loading }} loading="{{ . }}" {{- end }}
{{- with $referrerpolicy }} referrerpolicy="{{ . }}" {{- end }} {{- with $referrerpolicy }} referrerpolicy="{{ . }}" {{- end }}
{{- with $src }} src="{{ . }}" {{- end }} {{- with $src }} src="{{ . }}" {{- end }}

View File

@@ -464,26 +464,38 @@ func TestVimeoShortcode(t *testing.T) {
files := ` files := `
-- hugo.toml -- -- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] disableKinds = ['home','rss','section','sitemap','taxonomy','term']
privacy.vimeo.simple = false privacy.vimeo.simple = false
-- content/_index.md -- -- content/p1.md --
--- ---
title: home title: p1
--- ---
{{< vimeo 55073825 >}} {{< vimeo 55073825 >}}
-- layouts/index.html -- -- content/p2.md --
---
title: p2
---
{{< vimeo id=55073825 allowFullScreen=true >}}
-- content/p3.md --
---
title: p3
---
{{< vimeo id=55073825 allowFullScreen=false >}}
-- layouts/_default/single.html --
Hash: {{ .Content | hash.XxHash }} Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }} Content: {{ .Content }}
` `
// Regular mode // Regular mode
b := hugolib.Test(t, files) b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "d1f592d2256ac3ff") b.AssertFileContent("public/p1/index.html", "f7687b0c4e85b7d4")
b.AssertFileContent("public/p2/index.html", "f7687b0c4e85b7d4")
b.AssertFileContent("public/p3/index.html", "caca499bdc7f1e1e")
// Simple mode // Simple mode
files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true") files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true")
b = hugolib.Test(t, files) b = hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "c5bf16d87e2a370b") b.AssertFileContent("public/p1/index.html", "c5bf16d87e2a370b")
// Simple mode with non-existent id // Simple mode with non-existent id
files = strings.ReplaceAll(files, "{{< vimeo 55073825 >}}", "{{< vimeo __id_does_not_exist__ >}}") files = strings.ReplaceAll(files, "{{< vimeo 55073825 >}}", "{{< vimeo __id_does_not_exist__ >}}")
@@ -675,12 +687,12 @@ title: p2
b := hugolib.Test(t, files) b := hugolib.Test(t, files)
b.AssertFileContent("public/p1/index.html", "a0a6f5ade9cc3a9f") b.AssertFileContent("public/p1/index.html", "5156322adda11844")
b.AssertFileContent("public/p2/index.html", "289c655e727e596c") b.AssertFileContent("public/p2/index.html", "289c655e727e596c")
files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true") files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true")
b = hugolib.Test(t, files) b = hugolib.Test(t, files)
b.AssertFileContent("public/p1/index.html", "b76d790c20d2bd04") b.AssertFileContent("public/p1/index.html", "599174706edf963a")
b.AssertFileContent("public/p2/index.html", "a6db910a9cf54bc1") b.AssertFileContent("public/p2/index.html", "a6db910a9cf54bc1")
} }