mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
d0788b96ae
- Replace data.GetJSON calls with resources.GetRemote - Remove usage of Facebook’s oEmbed Read feature Fixes #11971
52 lines
2.1 KiB
HTML
52 lines
2.1 KiB
HTML
{{- $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 -}}
|