Skip to content

Commit

Permalink
attachments: sort output #23
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Jul 26, 2021
1 parent c62a9d1 commit bb5541f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions exampleSite/content/shortcodes/attachments.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -50,7 +51,6 @@ For example:

#### List of attachments ending in pdf or mp4


{{%/*attachments title="Related files" pattern=".*(pdf|mp4)"/*/%}}

renders as
Expand Down
3 changes: 2 additions & 1 deletion layouts/shortcodes/attachments.html
Original file line number Diff line number Diff line change
@@ -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">
Expand All @@ -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" }}
Expand Down

0 comments on commit bb5541f

Please sign in to comment.