-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathvimeo_simple.html
52 lines (51 loc) · 2.11 KB
/
vimeo_simple.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{{- $pc := site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- $ctx := dict "ctx" . }}
{{- if .IsNamedParams -}}
{{- with .Get "id" -}}
{{- $ctx = merge $ctx (dict "id" . "class" ($.Get "class")) -}}
{{- template "render-vimeo" $ctx -}}
{{- else -}}
{{- errorf "The %q shortcode requires a single named parameter, the ID of the Vimeo video. See %s" .Name .Position -}}
{{- end -}}
{{- else -}}
{{- with .Get 0 -}}
{{- $ctx = merge $ctx (dict "id" . "class" ($.Get 1)) -}}
{{- template "render-vimeo" $ctx -}}
{{- else -}}
{{- errorf "The %q shortcode requires a single positional parameter, the ID of the Vimeo video. See %s" .Name .Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "render-vimeo" -}}
{{- $dnt := cond site.Config.Privacy.Vimeo.EnableDNT 1 0 -}}
{{- $url := urls.JoinPath "https://vimeo.com" .id -}}
{{- $query := querify "url" $url "dnt" $dnt -}}
{{- $request := printf "https://vimeo.com/api/oembed.json?%s" $query -}}
{{- with try (resources.GetRemote $request) -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else with .Value -}}
{{- with . | transform.Unmarshal -}}
{{- $class := printf "%s %s" "s_video_simple" "__h_video" -}}
{{- with $.class -}}
{{- $class = printf "%s %s" "s_video_simple" . -}}
{{- else -}}
{{ template "__h_simple_css" $.ctx.Page }}
{{- end -}}
{{- $thumbnail := .thumbnail_url -}}
{{- $original := $thumbnail | replaceRE "(_.*\\.)" "." -}}
<div class="{{ $class }}">
<a href="{{ .provider_url }}{{ .video_id }}" rel="noopener" target="_blank">
<img src="{{ $thumbnail }}" srcset="{{ $thumbnail }} 1x, {{ $original }} 2x" alt="{{ .title }}">
<div class="play">
{{ template "__h_simple_icon_play" $.ctx.Page }}
</div>
</a>
</div>
{{- end -}}
{{- else -}}
{{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}