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