hugo/tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html

53 lines
2.1 KiB
HTML
Raw Permalink Normal View History

{{- $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 -}}
2018-05-29 18:48:36 -04:00
{{- end -}}