1
Fork 0
theorangeone.net-legacy/layouts/partials/list_item.html
Jake Howard f311220fe2
Allow unsplash images to be used
Oh my god Go templates are horrible!
2020-09-12 15:46:23 +01:00

26 lines
1.1 KiB
HTML

<div class="media list-page-item mb-3">
{{ if .Params.image }}
<div class="d-none d-md-block align-self-center img-wrapper mr-3">
<a href="{{ .RelPermalink }}">
{{ .Scratch.Set "image" .Params.image }}
{{ if hasPrefix .Params.image "resource:" }}
{{ $resource := .Resources.GetMatch (replace .Params.image "resource:" "") }}
{{ .Scratch.Set "image" ($resource.Resize "500x").RelPermalink }}
{{ else if hasPrefix .Params.image "unsplash:" }}
{{ $unsplash_id := replace .Params.image "unsplash:" "" }}
{{ $query := querify "client_id" (getenv "UNSPLASH_ACCESS_KEY") }}
{{ $unsplash_data := (getJSON "https://api.unsplash.com/photos/" $unsplash_id "?" $query )}}
{{ .Scratch.Set "image" $unsplash_data.urls.thumb }}
{{ end }}
<div class="image" data-image='{{ .Scratch.Get "image" }}'></div>
</a>
</div>
{{ end }}
<div class="media-body">
<a href="{{ .RelPermalink }}">
<h5 class="my-0">{{ .Title }}</h5>
</a>
<small>{{ partial "content-details.html" . }}</small>
<p>{{ partial "summary.html" . }}</p>
</div>
</div>