diff options
author | Helder Pereira <helfper@gmail.com> | 2021-10-28 22:04:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 22:04:10 +0300 |
commit | e817f53d690d35f181c896e0e320cb40f797e88c (patch) | |
tree | 0c292cec6bc3d2f9a2da50d7f8b8c2aa0a819ddc | |
parent | 3b9a4e7b00daae0e01b48d4151786791abbce562 (diff) |
-rw-r--r-- | exampleSite/content/shortcodes/attachments.en.files/small_file.txt | 1 | ||||
-rw-r--r-- | exampleSite/content/shortcodes/attachments.en.md | 10 | ||||
-rw-r--r-- | exampleSite/content/shortcodes/attachments.fr.files/small_file.txt | 1 | ||||
-rw-r--r-- | exampleSite/content/shortcodes/attachments.fr.md | 10 | ||||
-rw-r--r-- | i18n/ar.toml | 10 | ||||
-rw-r--r-- | i18n/de.toml | 10 | ||||
-rw-r--r-- | i18n/en.toml | 10 | ||||
-rw-r--r-- | i18n/es.toml | 10 | ||||
-rw-r--r-- | i18n/fr.toml | 10 | ||||
-rw-r--r-- | i18n/hi.toml | 10 | ||||
-rw-r--r-- | i18n/id.toml | 10 | ||||
-rw-r--r-- | i18n/ja.toml | 10 | ||||
-rw-r--r-- | i18n/nl.toml | 10 | ||||
-rw-r--r-- | i18n/pt.toml | 10 | ||||
-rw-r--r-- | i18n/ru.toml | 10 | ||||
-rw-r--r-- | i18n/tr.toml | 10 | ||||
-rw-r--r-- | i18n/zh-cn.toml | 10 | ||||
-rw-r--r-- | layouts/shortcodes/attachments.html | 66 |
18 files changed, 148 insertions, 70 deletions
diff --git a/exampleSite/content/shortcodes/attachments.en.files/small_file.txt b/exampleSite/content/shortcodes/attachments.en.files/small_file.txt new file mode 100644 index 0000000..32fa983 --- /dev/null +++ b/exampleSite/content/shortcodes/attachments.en.files/small_file.txt @@ -0,0 +1 @@ +This file was downloaded from Hugo Learn Theme. diff --git a/exampleSite/content/shortcodes/attachments.en.md b/exampleSite/content/shortcodes/attachments.en.md index 8a2429c..bea1350 100644 --- a/exampleSite/content/shortcodes/attachments.en.md +++ b/exampleSite/content/shortcodes/attachments.en.md @@ -39,23 +39,23 @@ That's all! |:--|:--|:--| | title | "Attachments" | List's title | | 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). +| pattern | ".*" | A regular expression, used to filter the attachments by file name. The **pattern** parameter value must be a [regular expression](https://en.wikipedia.org/wiki/Regular_expression). | For example: -* To match a file suffix of 'jpg', use **.*jpg** (not *.jpg). -* To match file names ending in 'jpg' or 'png', use **.*(jpg|png)** +* To match a file suffix of '.jpg', use `.*\.jpg$` (not `*.jpg`). +* To match file names ending in '.jpg' or '.png', use `.*\.(jpg|png)$`. ### Examples #### List of attachments ending in pdf or mp4 - {{%/*attachments title="Related files" pattern=".*(pdf|mp4)"/*/%}} + {{%/*attachments title="Related files" pattern=".*\.(pdf|mp4)$"/*/%}} renders as -{{%attachments title="Related files" pattern=".*(pdf|mp4)"/%}} +{{%attachments title="Related files" pattern=".*\.(pdf|mp4)$"/%}} #### Colored styled box diff --git a/exampleSite/content/shortcodes/attachments.fr.files/small_file.txt b/exampleSite/content/shortcodes/attachments.fr.files/small_file.txt new file mode 100644 index 0000000..10a3446 --- /dev/null +++ b/exampleSite/content/shortcodes/attachments.fr.files/small_file.txt @@ -0,0 +1 @@ +Ce fichier a été téléchargé à partir du Hugo Learn Theme. diff --git a/exampleSite/content/shortcodes/attachments.fr.md b/exampleSite/content/shortcodes/attachments.fr.md index c240939..49fc51b 100644 --- a/exampleSite/content/shortcodes/attachments.fr.md +++ b/exampleSite/content/shortcodes/attachments.fr.md @@ -39,23 +39,23 @@ C'est tout ! |:--|:--|:--| | title | "Pièces jointes" | Titre de la liste | | style | "" | Choisir entre "orange", "grey", "blue" et "green" pour un style plus sympa | -| pattern | ".*" | Une expression régulière, utilisée pour filtrer les pièces jointes par leur nom de fichier. <br/><br/>Le paramètre **pattern** doit être une [expression régulière](https://en.wikipedia.org/wiki/Regular_expression). +| pattern | ".*" | Une expression régulière, utilisée pour filtrer les pièces jointes par leur nom de fichier. Le paramètre **pattern** doit être une [expression régulière](https://en.wikipedia.org/wiki/Regular_expression). | Par exemple: -* Pour trouver les fichiers avec le suffixe 'jpg', utilisez **.*jpg** (pas *.jpg). -* Pour trouver les fichiers avec les suffixe 'jpg' ou 'png', utilisez **.*(jpg|png)** +* Pour trouver les fichiers avec le suffixe '.jpg', utilisez `.*\.jpg$` (pas `*.jpg`). +* Pour trouver les fichiers avec les suffixe '.jpg' ou '.png', utilisez `.*\.(jpg|png)$`. ### Exemples #### Lister les pièces jointes de type pdf ou mp4 - {{%/*attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/*/%}} + {{%/*attachments title="Fichiers associés" pattern=".*\.(pdf|mp4)$"/*/%}} s'affiche comme -{{%attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/%}} +{{%attachments title="Fichiers associés" pattern=".*\.(pdf|mp4)$"/%}} #### Modifier le style diff --git a/i18n/ar.toml b/i18n/ar.toml index cfce2ed..4cde5a6 100644 --- a/i18n/ar.toml +++ b/i18n/ar.toml @@ -25,5 +25,11 @@ other = "المزيد" [Expand-title] other = "...قم بتوسيع" -[BinaryPrefix-kilobyte] -other = "kb"
\ No newline at end of file +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/de.toml b/i18n/de.toml index 2d50ed3..d754294 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -25,5 +25,11 @@ other = "Mehr" [Expand-title] other = "Erweitere mich..." -[BinaryPrefix-kilobyte] -other = "kb"
\ No newline at end of file +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/en.toml b/i18n/en.toml index 7b7d0ca..1d2989b 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -25,5 +25,11 @@ other = "More" [Expand-title] other = "Expand me..." -[BinaryPrefix-kilobyte] -other = "kb"
\ No newline at end of file +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/es.toml b/i18n/es.toml index aad5aa3..15ce18a 100644 --- a/i18n/es.toml +++ b/i18n/es.toml @@ -25,5 +25,11 @@ other = "Más" [Expand-title] other = "Expandir..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/fr.toml b/i18n/fr.toml index 65bd26e..d993714 100644 --- a/i18n/fr.toml +++ b/i18n/fr.toml @@ -25,5 +25,11 @@ other = "Aller plus loin" [Expand-title] other = "Déroulez-moi..." -[BinaryPrefix-kilobyte] -other = "ko"
\ No newline at end of file +[Byte-symbol] +other = "o" + +[Kilobyte-symbol] +other = "ko" + +[Megabyte-symbol] +other = "Mo" diff --git a/i18n/hi.toml b/i18n/hi.toml index 8d19ca3..d853475 100644 --- a/i18n/hi.toml +++ b/i18n/hi.toml @@ -25,5 +25,11 @@ other = "अधिक सामग्री दिखाएं" [Expand-title] other = "विस्तार करे..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/id.toml b/i18n/id.toml index fac7e45..7803aa8 100644 --- a/i18n/id.toml +++ b/i18n/id.toml @@ -25,5 +25,11 @@ other = "Lainnya" [Expand-title] other = "Bentangkan..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/ja.toml b/i18n/ja.toml index 02769be..e9d72d3 100644 --- a/i18n/ja.toml +++ b/i18n/ja.toml @@ -25,5 +25,11 @@ other = "更に" [Expand-title] other = "開く..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/nl.toml b/i18n/nl.toml index b4d604b..bdba64f 100644 --- a/i18n/nl.toml +++ b/i18n/nl.toml @@ -25,5 +25,11 @@ other = "Snelkoppelingen" [Expand-title] other = "Lees meer..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/pt.toml b/i18n/pt.toml index 6575b4a..9622677 100644 --- a/i18n/pt.toml +++ b/i18n/pt.toml @@ -25,5 +25,11 @@ other = "Mais" [Expand-title] other = "Expandir..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/ru.toml b/i18n/ru.toml index 84b7df9..e82c31a 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -25,5 +25,11 @@ other = "Еще" [Expand-title] other = "Развернуть..." -[BinaryPrefix-kilobyte] -other = "килобайт"
\ No newline at end of file +[Byte-symbol] +other = "Б" + +[Kilobyte-symbol] +other = "КБ" + +[Megabyte-symbol] +other = "МБ" diff --git a/i18n/tr.toml b/i18n/tr.toml index c3affe3..27cfa21 100644 --- a/i18n/tr.toml +++ b/i18n/tr.toml @@ -25,5 +25,11 @@ other = "Dahası Var" [Expand-title] other = "Genişlet..." -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/i18n/zh-cn.toml b/i18n/zh-cn.toml index 4a6d435..4331cb3 100644 --- a/i18n/zh-cn.toml +++ b/i18n/zh-cn.toml @@ -25,5 +25,11 @@ other = "更多" [Expand-title] other = "展开" -[BinaryPrefix-kilobyte] -other = "kb" +[Byte-symbol] +other = "B" + +[Kilobyte-symbol] +other = "KB" + +[Megabyte-symbol] +other = "MB" diff --git a/layouts/shortcodes/attachments.html b/layouts/shortcodes/attachments.html index d688b71..2f0f8f3 100644 --- a/layouts/shortcodes/attachments.html +++ b/layouts/shortcodes/attachments.html @@ -1,36 +1,34 @@ -{{ $_hugo_config := `{ "version": 1 }` }} +{{ $_hugo_config := `{ "version": 1 }` -}} <section class="attachments {{ with .Get "style"}}{{.}}{{ end }}"> - <label> - <i class="fas fa-paperclip" aria-hidden="true"></i> - {{with .Get "title"}}{{.}}{{else}}{{T "Attachments-label"}}{{end}} - </label> - {{if eq .Page.File.BaseFileName "index"}} - {{$.Scratch.Add "filesName" "files"}} - {{else}} - {{$.Scratch.Add "filesName" (printf "%s.files" .Page.File.BaseFileName)}} - {{end}} - <div class="attachments-files"> - {{ range (readDir (printf "./content/%s%s" .Page.File.Dir ($.Scratch.Get "filesName")) ) }} - {{ $fileDir := replace $.Page.File.Dir "\\" "/" }} - {{if ($.Get "pattern")}} - {{if (findRE ($.Get "pattern") .Name)}} - <li> - <a href="{{ (printf "%s%s/%s" $fileDir ($.Scratch.Get "filesName") .Name) | relURL }}" > - {{.Name}} - </a> - ({{div .Size 1024 }} {{T "BinaryPrefix-kilobyte"}}) - </li> - {{end}} - {{else}} - <li> - <a href="{{ (printf "%s%s/%s" $fileDir ($.Scratch.Get "filesName") .Name) | relURL }}" > - {{.Name}} - </a> - ({{div .Size 1024 }} {{T "BinaryPrefix-kilobyte"}}) - </li> - {{end}} - {{end}} - </div> - {{.Inner}} + <label> + <i class="fas fa-paperclip" aria-hidden="true"></i> + {{with .Get "title"}}{{.}}{{else}}{{T "Attachments-label"}}{{end}} + </label> + <div class="attachments-files"> + {{- $filesName := "files" }} + {{- if ne .Page.File.BaseFileName "index" }} + {{- $filesName = printf "%s.files" .Page.File.BaseFileName }} + {{- end}} + {{- $fileDir := replace .Page.File.Dir "\\" "/" }} + {{- $pattern := .Get "pattern" | default "" }} + {{- range (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) }} + {{- if findRE $pattern .Name}} + {{- $size := .Size }} + {{- $unit := "Byte" }} + {{- if ge $size 1024 }} + {{- $size = div $size 1024 }} + {{- $unit = "Kilobyte" }} + {{- end}} + {{- if ge $size 1024 }} + {{- $size = div $size 1024 }} + {{- $unit = "Megabyte" }} + {{- end}} + <li> + <a href="{{ (printf "%s%s/%s" $fileDir $filesName .Name) | relLangURL }}">{{.Name}}</a> + ({{$size}} {{T (print $unit "-symbol")}}) + </li> + {{- end}} + {{- end}} + </div> + {{- .Inner}} </section> - |