From bb5541f79176f65cead764a86710ff2dc37536bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 26 Jul 2021 11:14:27 +0200 Subject: [PATCH] attachments: sort output #23 --- exampleSite/content/shortcodes/attachments.en.md | 4 ++-- layouts/shortcodes/attachments.html | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/exampleSite/content/shortcodes/attachments.en.md b/exampleSite/content/shortcodes/attachments.en.md index 8a2429cf30..0bce0e32ca 100644 --- a/exampleSite/content/shortcodes/attachments.en.md +++ b/exampleSite/content/shortcodes/attachments.en.md @@ -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.

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 diff --git a/layouts/shortcodes/attachments.html b/layouts/shortcodes/attachments.html index 7032a8023f..a240467584 100644 --- a/layouts/shortcodes/attachments.html +++ b/layouts/shortcodes/attachments.html @@ -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" }}
{{ $title }}
@@ -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" }}