up
This commit is contained in:
parent
a4a4702ce9
commit
4072e9888c
@ -28,7 +28,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// 1. Définissez votre FuncMap
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"hasSuffix": strings.HasSuffix,
|
"hasSuffix": strings.HasSuffix,
|
||||||
"ext": func(name string) string {
|
"ext": func(name string) string {
|
||||||
@ -36,13 +35,15 @@ func init() {
|
|||||||
},
|
},
|
||||||
"split": strings.Split,
|
"split": strings.Split,
|
||||||
"trimPrefix": strings.TrimPrefix,
|
"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(
|
templates = template.Must(
|
||||||
template.New("").
|
template.New("").
|
||||||
Funcs(funcMap).
|
Funcs(funcMap).
|
||||||
// ajuste le chemin vers vos .pages.tmpl
|
|
||||||
ParseGlob("./templates/*.pages.tmpl"),
|
ParseGlob("./templates/*.pages.tmpl"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
{{ with .Entry }}
|
{{ with .Entry }}
|
||||||
<h4 class="title is-5">{{ .Name }}</h4>
|
<h4 class="title is-5">{{ .Name }}</h4>
|
||||||
<p><strong>Type :</strong> {{ ext .Name }}</p>
|
<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>
|
<p><strong>Modifié le :</strong> {{ .ModTime.Format "02 Jan 2006 15:04" }}</p>
|
||||||
{{ if and (not .IsDir) (or (hasSuffix .Name ".jpg") (hasSuffix .Name ".png")) }}
|
{{ if and (not .IsDir) (or (hasSuffix .Name ".jpg") (hasSuffix .Name ".png")) }}
|
||||||
<figure class="image">
|
<figure class="image">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user