attachments: sort output #23

This commit is contained in:
Sören Weber 2021-07-26 11:14:27 +02:00
parent c62a9d1958
commit bb5541f791
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
2 changed files with 4 additions and 3 deletions

View file

@ -38,7 +38,8 @@ That's all!
| Parameter | Default | Description |
|:--|:--|:--|
| title | "Attachments" | List's title |
| style | "" | Choose between "orange", "grey", "blue" and "green" for nice style |
| sort | "asc" | Sorting the output in `asc`ending or `desc`ending order |
| style | "" | Choose between `orange`, `grey`, `blue` and `green` for nice style |
| pattern | ".*" | A regular expressions, used to filter the attachments by file name. <br/><br/>The **pattern** parameter value must be [regular expressions](https://en.wikipedia.org/wiki/Regular_expression).
For example:
@ -50,7 +51,6 @@ For example:
#### List of attachments ending in pdf or mp4
{{%/*attachments title="Related files" pattern=".*(pdf|mp4)"/*/%}}
renders as

View file

@ -1,6 +1,7 @@
{{ $_hugo_config := `{ "version": 1 }` }}
{{ $style := .Get "style" | default "neutral" }}
{{ $title := .Get "title" | default ("Attachments-label" | T) }}
{{ $sort := .Get "sort" | default "asc" }}
<section class="attachments {{ $style }}">
<div class="label">{{ $title }}</div>
<div class="attachments-files">
@ -11,7 +12,7 @@
{{- $fileDir := replace .Page.File.Dir "\\" "/" }}
{{- $pattern := .Get "pattern" | default "" }}
{{- range (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) }}
{{- range sort (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) "Name" $sort }}
{{- if findRE $pattern .Name}}
{{- $size := .Size }}
{{- $unit := "Byte-symbol" }}