www.byjp.me/layouts/shortcodes/book.html
2024-06-20 13:30:39 +01:00

36 lines
1.3 KiB
HTML

{{- define "partials/author-list.html" -}}
{{- $authors := . -}}
{{- if and (ne $authors nil) (gt (len $authors) 0) -}}
<span class="authors list">
{{- " by " -}}
{{- range $i, $a := $authors -}}
{{- if and (ne $i 0) (eq (add $i 1) (len $authors)) -}}and {{ end -}}
<a href="{{ $a.url }}" target="_blank">{{ $a.name }}</a>
{{- if ne (add $i 1) (len $authors) -}}, {{ end -}}
{{- end -}}
</span>
{{- end -}}
{{- end -}}
{{- $showCover := ne (.Get 1) false -}}
{{- $book := partial "openlibrary.obj" (dict "path" .Page.Path "id" (.Get 0)) -}}
{{- with $book -}}
{{- if and $showCover .cover -}}
<figure class="book">
<a href="{{ .url }}" target="_blank" title="Open book details">
{{- $title := .title -}}
{{- with .cover -}}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="The cover of the book {{ $title }}">
{{- end -}}
</a>
<figcaption>
<cite><a href="{{ .url }}" target="_blank" title="Open book details">{{ .title }}</a></cite>
{{- partial "partials/author-list.html" .authors -}}
</figcaption>
</figure>
{{- else -}}
<cite><a href="{{ .url }}" target="_blank" title="Open book details">{{ .title }}</a></cite>
{{- partial "partials/author-list.html" .authors -}}
{{- end -}}
{{- end -}}