attachments: fix search dir and link if contentDir in multilang config is used #105

This commit is contained in:
Sören Weber 2021-09-28 21:24:30 +02:00
parent 16b346c646
commit a0e5194c00
No known key found for this signature in database
GPG Key ID: 07D17FF580AE7589
3 changed files with 10 additions and 4 deletions

View File

@ -0,0 +1 @@
Harrr, nothn' to see herre

View File

@ -2,4 +2,6 @@
descrption = "Th' Attachments shorrrtcode displays a list o' files attached t' a plank" descrption = "Th' Attachments shorrrtcode displays a list o' files attached t' a plank"
title = "Attachments" title = "Attachments"
+++ +++
{{% attachments /%}}
{{< piratify >}} {{< piratify >}}

View File

@ -10,9 +10,12 @@
{{- $filesName = printf "%s.files" .Page.File.BaseFileName }} {{- $filesName = printf "%s.files" .Page.File.BaseFileName }}
{{- end}} {{- end}}
{{- $fileDir := replace .Page.File.Dir "\\" "/" }} {{- $fileLink := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }}
{{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }}
{{- $fileDir := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }}
{{- $fileDir = replace $fileDir "\\" "/" }}
{{- $pattern := .Get "pattern" | default "" }} {{- $pattern := .Get "pattern" | default "" }}
{{- range sort (readDir (printf "content/%s%s" .Page.File.Dir $filesName) ) "Name" $sort }} {{- range sort (readDir (printf "%s%s" $fileDir $filesName) ) "Name" $sort }}
{{- if findRE $pattern .Name}} {{- if findRE $pattern .Name}}
{{- $size := .Size }} {{- $size := .Size }}
{{- $unit := "Byte-symbol" }} {{- $unit := "Byte-symbol" }}
@ -25,7 +28,7 @@
{{- $unit = "Megabyte-symbol" }} {{- $unit = "Megabyte-symbol" }}
{{- end }} {{- end }}
{{- $unitsymbol := $unit | T }} {{- $unitsymbol := $unit | T }}
<li><a href="{{ (printf "%s%s/%s" $fileDir $filesName .Name) | relLangURL }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li> <li><a href="{{ (printf "%s%s/%s" $fileLink $filesName .Name) | relURL }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
{{- end }} {{- end }}
{{- end }} {{- end }}
</ul> </ul>