blob: e262d3c3cb05c22d3b14599268ea24441fb8d45c (
plain)
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 := .Page.Site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- $ctx := dict "page" .Page "pc" $pc "name" .Name "position" .Position }}
{{- if .IsNamedParams -}}
{{- with .Get "id" -}}
{{- $ctx = merge $ctx (dict "id" . "class" ($.Get "class")) -}}
{{- template "render-vimeo" $ctx -}}
{{- else -}}
{{- errorf "The %q shortocde 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 shortocde requires a single positional parameter, the ID of the Vimeo video. See %s" .Name .Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "render-vimeo" -}}
{{- $dnt := cond .pc.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 resources.GetRemote $request -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else -}}
{{- 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" $.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" $.page }}
</div>
</a>
</div>
{{- end -}}
{{- end -}}
{{- else -}}
{{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
{{- end -}}
{{- end -}}
|