Page de statistiques
This commit is contained in:
28
layouts/shortcodes/stats-var.html
Normal file
28
layouts/shortcodes/stats-var.html
Normal file
@@ -0,0 +1,28 @@
|
||||
{{- $key := .Get "key" | default (.Get 0) -}}
|
||||
{{- if not $key -}}
|
||||
{{- warnf "stats-var: key manquante" -}}
|
||||
{{- else -}}
|
||||
{{- $resource := .Page.Resources.GetMatch "data/stats.json" -}}
|
||||
{{- if not $resource -}}
|
||||
{{- warnf "stats-var: data/stats.json introuvable pour %s" .Page.File.Path -}}
|
||||
{{- else -}}
|
||||
{{- $data := $resource | transform.Unmarshal -}}
|
||||
{{- $value := "" -}}
|
||||
|
||||
{{- if eq $key "generated_at" -}}
|
||||
{{- with $data.generated_at -}}
|
||||
{{- $value = time . | time.Format "02/01/2006 à 15:04" -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- range $section := $data.sections -}}
|
||||
{{- range $stat := (default (slice) $section.statistics) -}}
|
||||
{{- if eq $stat.key $key -}}
|
||||
{{- $value = (default "" $stat.value) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user