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"
title = "Attachments"
+++
{{% attachments /%}}
{{< piratify >}}

View file

@ -10,9 +10,12 @@
{{- $filesName = printf "%s.files" .Page.File.BaseFileName }}
{{- 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 "" }}
{{- 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}}
{{- $size := .Size }}
{{- $unit := "Byte-symbol" }}
@ -25,7 +28,7 @@
{{- $unit = "Megabyte-symbol" }}
{{- end }}
{{- $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 }}
</ul>