mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-22 01:30:52 +02:00
Refactor: - business JSON-LD - site_head - Slider - Gallery - Video Gallery is now intended only for local images in the page bundle (so that they can be optimized by Hugo). Close #2119
35 lines
No EOL
1.4 KiB
HTML
35 lines
No EOL
1.4 KiB
HTML
{{/* Video Shortcode for Wowchemy. */}}
|
|
{{/* Load video from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
|
|
|
|
{{ $destination := .Get "src" }}
|
|
{{ $video_ext_with_dot := path.Ext (.Get "src") }}
|
|
{{ $video_ext := strings.TrimPrefix "." $video_ext_with_dot }}
|
|
{{ $video_type := $video_ext }}
|
|
{{ $destination_preview := (.Get "poster") | default (replace $destination $video_ext_with_dot ".jpg") }}
|
|
{{ $is_remote := strings.HasPrefix $destination "http" }}
|
|
{{- $asset := "" -}}
|
|
{{- $asset_preview := "" -}}
|
|
{{- if not $is_remote -}}
|
|
{{- $asset = (.Page.Resources.ByType "video").GetMatch $destination -}}
|
|
{{- $asset_preview = (.Page.Resources.ByType "image").GetMatch $destination_preview -}}
|
|
{{- if not $asset -}}
|
|
{{- $asset = resources.Get (path.Join "media" $destination) -}}
|
|
{{- $asset_preview = resources.Get (path.Join "media" $destination_preview) -}}
|
|
{{- end -}}
|
|
{{ $video_type = $asset.MediaType.SubType }}
|
|
{{- end -}}
|
|
|
|
{{ if $asset }}
|
|
{{ $destination = $asset.RelPermalink }}
|
|
{{ else }}
|
|
{{ $destination = $destination | safeURL }}
|
|
{{ end }}
|
|
|
|
{{ $poster := (.Get "poster") | default "" }}
|
|
{{ if $asset_preview }}
|
|
{{ $poster = $asset_preview.RelPermalink }}
|
|
{{ end }}
|
|
|
|
<video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}} {{ with (.Get "id") }}id="video-{{.|anchorize}}"{{end}}>
|
|
<source src="{{$destination}}" type="video/{{$video_type}}">
|
|
</video> |