2024-02-29 19:45:01 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2024-09-14 23:23:35 +00:00
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'resources' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/releasenotes/5/#5180" $page.File.Filename }}
2024-02-29 19:45:01 +00:00
{{- end }}
{{- $color := .color | default "" }}
{{- $style := .style | default "default" }}
{{- if and (not $color) (eq (len $color) 0) }}
{{- $style = .style | default "transparent" }}
{{- end }}
2024-09-12 05:55:24 +00:00
{{- $boxStyle := partial "_relearn/boxStyle.gotmpl" (dict "style" $style "title" .title "icon" .icon) }}
{{- $title := trim ($boxStyle.title | default ("Attachments-label" | T)) " " }}
{{- $icon := trim ($boxStyle.icon | default "paperclip") " " }}
2024-02-29 19:45:01 +00:00
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
2024-09-05 19:25:52 +00:00
{{- $expander := false }}
{{- $expanded := .expanded | default "" }}
{{- if eq (printf "%T" $expanded) "string" }}
{{- if ne (trim $expanded " ") "" }}
{{- $expander = true }}
{{- $expanded = (eq $expanded "true") }}
{{- end }}
{{- else }}
{{- $expander = true }}
{{- end }}
2024-02-29 19:45:01 +00:00
{{- $sort := .sort | default "asc" }}
{{- $pattern := .pattern | default "" }}
2024-09-05 19:25:52 +00:00
{{- if eq $page.BundleType "" }}
2024-04-24 20:42:49 +00:00
{{- warnf "%q: UNSUPPORTED usage of 'resources' shortcode found, use a page bundle instead; see https://mcshelby.github.io/hugo-theme-relearn/shortcodes/resources" $page.File.Filename }}
2024-09-05 19:25:52 +00:00
{{- end }}
{{- $content := partial "inline/resource-list" (dict
"page" $page
"sort" $sort
"pattern" $pattern
) }}
{{- partial "shortcodes/notice.html" (dict
"page" $page
"class" "attachments"
"containerstyle" "ul"
"containerclass" (slice "attachments-files")
"color" $color
"content" $content
"expanded" $expanded
"icon" $icon
"style" $style
"title" $title
) }}
{{- define "partials/inline/resource-list" }}
{{- $sort := .sort }}
{{- $pattern := .pattern }}
{{- with .page }}
{{- range sort .Resources "Name" $sort }}
{{- if findRE $pattern .Name }}
{{- $size := len .Content }}
{{- $unit := "Byte-symbol" }}
{{- if ge $size 1024 }}
{{- $size = div $size 1024 }}
{{- $unit = "Kilobyte-symbol" }}
{{- end }}
{{- if ge $size 1024 }}
{{- $size = div $size 1024 }}
{{- $unit = "Megabyte-symbol" }}
{{- end }}
{{- $unitsymbol := $unit | T }}
< li > < a href = "{{ .RelPermalink }}" > {{.Name}}< / a > ({{$size}} {{$unitsymbol}})< / li >
{{- end }}
2024-02-29 19:45:01 +00:00
{{- end }}
{{- end }}
{{- end }}