This commit is contained in:
julien 2025-06-20 16:40:04 +02:00
parent a4a4702ce9
commit 4072e9888c
2 changed files with 5 additions and 4 deletions

View File

@ -28,7 +28,6 @@ var (
)
func init() {
// 1. Définissez votre FuncMap
funcMap := template.FuncMap{
"hasSuffix": strings.HasSuffix,
"ext": func(name string) string {
@ -36,13 +35,15 @@ func init() {
},
"split": strings.Split,
"trimPrefix": strings.TrimPrefix,
// nouveau helper pour convertir bytes -> kilobytes
"toKB": func(size int64) float64 {
return float64(size) / 1024
},
}
// 2. Parsez tous les templates EN UNE FOIS, en injectant le FuncMap
templates = template.Must(
template.New("").
Funcs(funcMap).
// ajuste le chemin vers vos .pages.tmpl
ParseGlob("./templates/*.pages.tmpl"),
)
}

View File

@ -2,7 +2,7 @@
{{ with .Entry }}
<h4 class="title is-5">{{ .Name }}</h4>
<p><strong>Type :</strong> {{ ext .Name }}</p>
<p><strong>Taille :</strong> {{ printf "%.1f KB" (float64 .Size/1024) }}</p>
<p><strong>Taille :</strong> {{ printf "%.1f KB" (toKB .Size) }}</p>
<p><strong>Modifié le :</strong> {{ .ModTime.Format "02 Jan 2006 15:04" }}</p>
{{ if and (not .IsDir) (or (hasSuffix .Name ".jpg") (hasSuffix .Name ".png")) }}
<figure class="image">