tcharles.fr/layouts/shortcodes/cinema.html
2025-02-07 20:32:59 +01:00

41 lines
1.2 KiB
HTML

{{ $path := .Get "path" }}
{{ $metadata_path := (path.Dir $path) | printf "%s/metadata.yaml" }}
{{ $files := sort (resources.Match $path) "Name" }}
{{ $metadata := "" }}
{{ with resources.Get $metadata_path }}
{{ with . | transform.Unmarshal }}
{{ $metadata = . }}
{{ else }}
{{ errorf "failed to parse %q" $metadata_path }}
{{ end }}
{{ else }}
{{ errorf "Unable to get global resource %q" $metadata_path }}
{{ end }}
<div class="cinema {{ .Get "class" }}" >
{{ range $files }}
{{ $basename := path.BaseName (.RelPermalink) }}
{{ $title := (index $metadata $basename).title }}
{{ if eq .MediaType.MainType "image" }}
<a
data-lightbox="{{ $path | hash.XxHash }}"
href="{{ .RelPermalink }}"
title="{{ $title}}">
{{ with .Resize "x150" }}
<img src="{{ .RelPermalink }}" alt="{{ $title }}">
{{ end }}
</a>
{{ else if eq .MediaType.MainType "video" }}
<video controls>
<source src="{{ .RelPermalink }}" type="{{ .MediaType }}"/>
<a href="{{ .RelPermalink }}">Download video</a>
</video>
{{ end }}
{{ else }}
{{ errorf "Unable to get page resource %q" $path }}
{{ end }}
</div>