Skip to content

Commit 8de5324

Browse files
onedrawingperdaybep
authored andcommitted
Add vimeo_simple
Fixes #4749
1 parent 20cbc2c commit 8de5324

File tree

6 files changed

+129
-9
lines changed

6 files changed

+129
-9
lines changed

config/privacy/privacyConfig.go

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ type Twitter struct {
8282
// Vimeo holds the privacy configuration settingsrelated to the Vimeo shortcode.
8383
type Vimeo struct {
8484
Service `mapstructure:",squash"`
85+
86+
// If simple mode is enabled, only a thumbnail is fetched from i.vimeocdn.com and
87+
// shown with a play button overlaid. If a user clicks the button, he/she will
88+
// be taken to the video page on vimeo.com in a new browser tab.
89+
Simple bool
8590
}
8691

8792
// YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.

config/privacy/privacyConfig_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ disable = true
4646
enableDNT = true
4747
[privacy.vimeo]
4848
disable = true
49+
simple = true
4950
[privacy.youtube]
5051
disable = true
5152
privacyEnhanced = true
@@ -69,7 +70,7 @@ simple = true
6970
assert.True(pc.Twitter.Disable)
7071
assert.True(pc.Twitter.EnableDNT)
7172
assert.True(pc.Vimeo.Disable)
72-
73+
assert.True(pc.Vimeo.Simple)
7374
assert.True(pc.YouTube.PrivacyEnhanced)
7475
assert.True(pc.YouTube.Disable)
7576
}

tpl/tplimpl/embedded/templates.autogen.go

+62-4
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,41 @@ if (!doNotTrack) {
269269
<!-- Output all taxonomies as schema.org keywords -->
270270
<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
271271
{{ end }}`},
272+
{`shortcodes/__h_simple_assets.html`, `{{ define "__h_simple_css" }}{{/* These template definitions are global. */}}
273+
{{- if not (.Page.Scratch.Get "__h_simple_css") -}}
274+
{{/* Only include once */}}
275+
{{- .Page.Scratch.Set "__h_simple_css" true -}}
276+
<style>
277+
.__h_video {
278+
position: relative;
279+
padding-bottom: 56.23%;
280+
height: 0;
281+
overflow: hidden;
282+
width: 100%;
283+
background: #000;
284+
}
285+
.__h_video img {
286+
max-width: 100%;
287+
height: auto;
288+
color: #000;
289+
}
290+
.__h_video .play {
291+
height: 72px;
292+
width: 72px;
293+
left: 50%;
294+
top: 50%;
295+
margin-left: -36px;
296+
margin-top: -36px;
297+
position: absolute;
298+
cursor: pointer;
299+
}
300+
</style>
301+
{{- end -}}
302+
{{- end -}}
303+
{{- define "__h_simple_icon_play" -}}
304+
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 61 61"><circle cx="30.5" cy="30.5" r="30.5" opacity=".8" fill="#000"></circle><path d="M25.3 19.2c-2.1-1.2-3.8-.2-3.8 2.2v18.1c0 2.4 1.7 3.4 3.8 2.2l16.6-9.1c2.1-1.2 2.1-3.2 0-4.4l-16.6-9z" fill="#fff"></path></svg>
305+
{{- end -}}
306+
`},
272307
{`shortcodes/figure.html`, `<!-- image -->
273308
<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
274309
{{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
@@ -361,14 +396,37 @@ if (!doNotTrack) {
361396
{{- end -}}`},
362397
{`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
363398
{{- if not $pc.Disable -}}
364-
{{ if .IsNamedParams }}<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
365-
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
399+
{{- if $pc.Simple -}}
400+
{{ template "_internal/shortcodes/vimeo_simple.html" . }}
401+
{{- else -}}
402+
{{ if .IsNamedParams }}<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"{{ end }}>
403+
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
366404
</div>{{ else }}
367-
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
368-
<iframe src="//player.vimeo.com/video/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
405+
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"{{ end }}>
406+
<iframe src="//player.vimeo.com/video/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
369407
</div>
370408
{{ end }}
409+
{{- end -}}
371410
{{- end -}}`},
411+
{`shortcodes/vimeo_simple.html`, `{{ $id := .Get "id" | default (.Get 0) }}
412+
{{- $item := getJSON "https://vimeo.com/api/oembed.json?url=https://vimeo.com/" $id -}}
413+
{{ $class := .Get "class" | default (.Get 1) }}
414+
{{ $hasClass := $class }}
415+
{{ $class := $class | default "__h_video" }}
416+
{{ if not $hasClass }}
417+
{{/* If class is set, assume the user wants to provide his own styles. */}}
418+
{{ template "__h_simple_css" $ }}
419+
{{ end }}
420+
{{ $secondClass := "s_video_simple" }}
421+
<div class="{{ $secondClass }} {{ $class }}">
422+
{{- with $item }}
423+
<a href="{{ .provider_url }}{{ .video_id | safeHTMLAttr }}" target="_blank">
424+
{{ $thumb := .thumbnail_url }}
425+
{{ $original := $thumb | replaceRE "(_.*\\.)" "." }}
426+
<img src="{{ $thumb }}" srcset="{{ $thumb }} 1x, {{ $original }} 2x" alt="{{ .title }}">
427+
<div class="play">{{ template "__h_simple_icon_play" $ }}</div></a></div>
428+
{{- end -}}
429+
`},
372430
{`shortcodes/youtube.html`, `{{- $pc := .Page.Site.Config.Privacy.YouTube -}}
373431
{{- if not $pc.Disable -}}
374432
{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{ define "__h_simple_css" }}{{/* These template definitions are global. */}}
2+
{{- if not (.Page.Scratch.Get "__h_simple_css") -}}
3+
{{/* Only include once */}}
4+
{{- .Page.Scratch.Set "__h_simple_css" true -}}
5+
<style>
6+
.__h_video {
7+
position: relative;
8+
padding-bottom: 56.23%;
9+
height: 0;
10+
overflow: hidden;
11+
width: 100%;
12+
background: #000;
13+
}
14+
.__h_video img {
15+
max-width: 100%;
16+
height: auto;
17+
color: #000;
18+
}
19+
.__h_video .play {
20+
height: 72px;
21+
width: 72px;
22+
left: 50%;
23+
top: 50%;
24+
margin-left: -36px;
25+
margin-top: -36px;
26+
position: absolute;
27+
cursor: pointer;
28+
}
29+
</style>
30+
{{- end -}}
31+
{{- end -}}
32+
{{- define "__h_simple_icon_play" -}}
33+
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 61 61"><circle cx="30.5" cy="30.5" r="30.5" opacity=".8" fill="#000"></circle><path d="M25.3 19.2c-2.1-1.2-3.8-.2-3.8 2.2v18.1c0 2.4 1.7 3.4 3.8 2.2l16.6-9.1c2.1-1.2 2.1-3.2 0-4.4l-16.6-9z" fill="#fff"></path></svg>
34+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
22
{{- if not $pc.Disable -}}
3-
{{ if .IsNamedParams }}<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
4-
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
3+
{{- if $pc.Simple -}}
4+
{{ template "_internal/shortcodes/vimeo_simple.html" . }}
5+
{{- else -}}
6+
{{ if .IsNamedParams }}<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"{{ end }}>
7+
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
58
</div>{{ else }}
6-
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
7-
<iframe src="//player.vimeo.com/video/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
9+
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"{{ end }}>
10+
<iframe src="//player.vimeo.com/video/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
811
</div>
912
{{ end }}
13+
{{- end -}}
1014
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{ $id := .Get "id" | default (.Get 0) }}
2+
{{- $item := getJSON "https://vimeo.com/api/oembed.json?url=https://vimeo.com/" $id -}}
3+
{{ $class := .Get "class" | default (.Get 1) }}
4+
{{ $hasClass := $class }}
5+
{{ $class := $class | default "__h_video" }}
6+
{{ if not $hasClass }}
7+
{{/* If class is set, assume the user wants to provide his own styles. */}}
8+
{{ template "__h_simple_css" $ }}
9+
{{ end }}
10+
{{ $secondClass := "s_video_simple" }}
11+
<div class="{{ $secondClass }} {{ $class }}">
12+
{{- with $item }}
13+
<a href="{{ .provider_url }}{{ .video_id | safeHTMLAttr }}" target="_blank">
14+
{{ $thumb := .thumbnail_url }}
15+
{{ $original := $thumb | replaceRE "(_.*\\.)" "." }}
16+
<img src="{{ $thumb }}" srcset="{{ $thumb }} 1x, {{ $original }} 2x" alt="{{ .title }}">
17+
<div class="play">{{ template "__h_simple_icon_play" $ }}</div></a></div>
18+
{{- end -}}

0 commit comments

Comments
 (0)