Skip to content

Commit 5c49140

Browse files
authored
tpl/tplimpl: Fix allowFullScreen option in Vimeo and YouTube shortcodes
Closes #13650
1 parent 75b219d commit 5c49140

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

‎tpl/tplimpl/embedded/templates/_shortcodes/vimeo.html‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
Accepts named or positional arguments. If positional, order is id, class,
55
title, then loading.
66

7-
@param {string} [id] The video id. Optional if the id is provided as first positional argument.
7+
@param {bool} [allowFullScreen=true] Whether the iframe element can activate full screen mode.
88
@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.
9+
@param {string} [id] The video id. Optional if the id is the first and only positional argument.
910
@param {string} [loading=eager] The loading attribute of the iframe element.
1011
@param {string} [title=Vimeo video] The title attribute of the iframe element.
11-
@param {bool} [allowFullScreen=true] Whether the iframe element can activate full screen mode.
1212

1313
@returns {template.HTML}
1414

@@ -22,16 +22,16 @@
2222
{{- else }}
2323
{{- $dnt := cond $pc.EnableDNT 1 0 }}
2424

25-
{{- $id := or (.Get "id") (.Get 0) "" }}
26-
{{- $class := or (.Get "class") (.Get 1) "" }}
27-
{{- $title := or (.Get "title") (.Get 2) "Vimeo video" }}
28-
{{- $loading := or (.Get "loading") (.Get 3) "eager" }}
29-
{{- $allowFullScreen := or (.Get "allowFullScreen") (.Get 4) true }}
25+
{{- $allowFullScreen := true }}
26+
{{- $class := or (.Get "class") }}
27+
{{- $id := or (.Get "id") (.Get 0) }}
28+
{{- $loading := or (.Get "loading") }}
29+
{{- $title := or (.Get "title") }}
3030

31-
{{- if in (slice "false" false 0) ($.Get "allowFullScreen") }}
32-
{{- $allowFullScreen = false }}
33-
{{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
31+
{{- if in (slice "true" true 1) (.Get "allowFullScreen") }}
3432
{{- $allowFullScreen = true }}
33+
{{- else if in (slice "false" false 0) (.Get "allowFullScreen") }}
34+
{{- $allowFullScreen = false }}
3535
{{- end }}
3636

3737
{{- $iframeAllowList := "" }}

‎tpl/tplimpl/embedded/templates/_shortcodes/youtube.html‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@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.
77
@param {bool} [controls=true] Whether to display the video controls.
88
@param {int} [end] The time, measured in seconds from the start of the video, when the player should stop playing the video.
9-
@param {string} [id] The video id. Optional if the id is provided as first positional argument.
9+
@param {string} [id] The video id. Optional if the id is the first and only positional argument.
1010
@param {string} [loading=eager] The loading attribute of the iframe element.
1111
@param {bool} [loop=false] Whether to indefinitely repeat the video. Ignores the start and end arguments after the first play.
1212
@param {bool} [mute=false] Whether to mute the video. Always true when autoplay is true.
@@ -41,34 +41,41 @@
4141

4242
{{- /* Get arguments. */}}
4343
{{- if in (slice "true" true 1) ($.Get "allowFullScreen") }}
44-
{{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
44+
{{- $allowFullScreen = true }}
45+
{{- else if in (slice "false" false 0) ($.Get "allowFullScreen") }}
46+
{{- $allowFullScreen = false }}
4547
{{- end }}
46-
{{- if in (slice "false" false 0) ($.Get "autoplay") }}
47-
{{- $autoplay = 0 }}
48-
{{- else if in (slice "true" true 1) ($.Get "autoplay") }}
48+
{{- if in (slice "true" true 1) ($.Get "autoplay") }}
4949
{{- $autoplay = 1 }}
50+
{{- else if in (slice "false" false 0) ($.Get "autoplay") }}
51+
{{- $autoplay = 0 }}
5052
{{- end }}
51-
{{- if in (slice "false" false 0) ($.Get "controls") }}
52-
{{- $controls = 0 }}
53-
{{- else if in (slice "true" true 1) ($.Get "controls") }}
53+
{{- if in (slice "true" true 1) ($.Get "controls") }}
5454
{{- $controls = 1 }}
55+
{{- else if in (slice "false" false 0) ($.Get "controls") }}
56+
{{- $controls = 0 }}
5557
{{- end }}
56-
{{- if in (slice "false" false 0) ($.Get "loop") }}
57-
{{- $loop = 0 }}
58-
{{- else if in (slice "true" true 1) ($.Get "loop") }}
58+
{{- if in (slice "true" true 1) ($.Get "loop") }}
5959
{{- $loop = 1 }}
60+
{{- else if in (slice "false" false 0) ($.Get "loop") }}
61+
{{- $loop = 0 }}
6062
{{- end }}
61-
{{- if in (slice "false" false 0) ($.Get "mute") }}
62-
{{- $mute = 0 }}
63-
{{- else if or (in (slice "true" true 1) ($.Get "mute")) $autoplay }}
63+
{{- if or (in (slice "true" true 1) ($.Get "mute")) $autoplay }}
6464
{{- $mute = 1 }}
65+
{{- else if in (slice "false" false 0) ($.Get "mute") }}
66+
{{- $mute = 0 }}
6567
{{- end }}
6668
{{- $class := or ($.Get "class") $class }}
6769
{{- $end := or ($.Get "end") $end }}
6870
{{- $loading := or ($.Get "loading") $loading }}
6971
{{- $start := or ($.Get "start") $start }}
7072
{{- $title := or ($.Get "title") $title }}
7173

74+
{{- /* Adjust iframeAllowList. */}}
75+
{{- if $allowFullScreen }}
76+
{{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
77+
{{- end }}
78+
7279
{{- /* Define src attribute. */}}
7380
{{- $host := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }}
7481
{{- $src := printf "https://%s/embed/%s" $host $id }}

‎tpl/tplimpl/shortcodes_integration_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ Content: {{ .Content }}
488488

489489
// Regular mode
490490
b := hugolib.Test(t, files)
491-
b.AssertFileContent("public/p1/index.html", "f7687b0c4e85b7d4")
492-
b.AssertFileContent("public/p2/index.html", "f7687b0c4e85b7d4")
493-
b.AssertFileContent("public/p3/index.html", "caca499bdc7f1e1e")
491+
b.AssertFileContent("public/p1/index.html", "82566e6b8d04b53e")
492+
b.AssertFileContent("public/p2/index.html", "82566e6b8d04b53e")
493+
b.AssertFileContent("public/p3/index.html", "2b5f9cc3167d1336")
494494

495495
// Simple mode
496496
files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true")
@@ -687,12 +687,12 @@ title: p2
687687

688688
b := hugolib.Test(t, files)
689689

690-
b.AssertFileContent("public/p1/index.html", "5156322adda11844")
690+
b.AssertFileContent("public/p1/index.html", "4b54bf9bd03946ec")
691691
b.AssertFileContent("public/p2/index.html", "289c655e727e596c")
692692

693693
files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true")
694694

695695
b = hugolib.Test(t, files)
696-
b.AssertFileContent("public/p1/index.html", "599174706edf963a")
696+
b.AssertFileContent("public/p1/index.html", "78eb19b5c6f3768f")
697697
b.AssertFileContent("public/p2/index.html", "a6db910a9cf54bc1")
698698
}

0 commit comments

Comments
 (0)