{{- /* resource-tiles — display a page's file resources as a responsive grid of cards ("tiles"), each with a thumbnail, a title, the file size and a download link. Handy for a downloads page that offers a handful of PDFs, spreadsheets, archives, … Params: match glob selecting which page resources to show (default "*.pdf") cols number of columns on large screens (default 3) sort resource field to order by: "title", "name" or "weight" (default: the order they appear in front matter) class extra CSS classes for the wrapping row Thumbnails are resolved per resource, in order of preference: 1. a `thumbnail` param on the resource, pointing at an image in the same page bundle 2. an image resource whose name matches the file, e.g. `report.png` or `report.pdf.png` next to `report.pdf` 3. a generic file icon showing the upper-cased extension Per-resource metadata is read from the page's front matter: resources: - src: report.pdf title: Annual report params: description: Everything that happened last year. thumbnail: report-cover.png */ -}} {{- $page := .Page -}} {{- $match := or (.Get "match") "*.pdf" -}} {{- $cols := or (.Get "cols") 3 -}} {{- $class := .Get "class" -}} {{- $imgExts := slice "png" "jpg" "jpeg" "webp" "gif" "avif" -}} {{- $resources := $page.Resources.Match $match -}} {{- with .Get "sort" -}} {{- $resources = sort $resources . -}} {{- end -}} {{- with $resources -}}
{{- range . }} {{- $res := . -}} {{- $ext := strings.TrimPrefix "." (path.Ext .Name) -}} {{- /* Title: front-matter `title`, else the humanized file name. Hugo falls back .Title to .Name, so treat that as unset. */ -}} {{- $title := .Title -}} {{- if or (not $title) (eq $title .Name) -}} {{- $title = humanize (path.BaseName .Name) -}} {{- end -}} {{- /* Resolve a thumbnail image (see the doc comment above). */ -}} {{- $thumb := false -}} {{- with .Params.thumbnail -}} {{- $thumb = $page.Resources.GetMatch . -}} {{- end -}} {{- if not $thumb -}} {{- $base := path.BaseName $res.Name -}} {{- range $imgExts -}} {{- if not $thumb -}} {{- $thumb = or ($page.Resources.GetMatch (printf "%s.%s" $base .)) ($page.Resources.GetMatch (printf "%s.%s" $res.Name .)) -}} {{- end -}} {{- end -}} {{- end -}} {{- if and $thumb (eq $thumb.ResourceType "image") -}} {{- $thumb = $thumb.Fill "600x400 Center" -}} {{- end -}}
{{- if $thumb }} {{ $title }} {{- else }} {{- end }}
{{ $title }}
{{- with $res.Params.description }}

{{ $page.RenderString . }}

{{- end }}
{{- end }}
{{- end -}}