Files
alphabreed/hugo/content/comics/_content.gotmpl
2026-01-14 23:24:24 +01:00

44 lines
1.3 KiB
Go Template

{{ $basePath := "content/comics" }}
{{ range (os.ReadDir $basePath) }}
{{ if .IsDir }}
{{ $comicDir := .Name }}
{{ $fullPath := printf "%s/%s" $basePath $comicDir }}
{{ $indexContent := readFile (printf "%s/_index.md" $fullPath) }}
{{ $comicData := transform.Unmarshal $indexContent }}
{{ $images := slice }}
{{ range (os.ReadDir $fullPath) }}
{{ if findRE "\\.(jpg|jpeg|png|webp|gif)$" .Name }}
{{ $images = $images | append .Name }}
{{ end }}
{{ end }}
{{ $images = sort $images }}
{{ $imageCount := len $images }}
{{ range $index, $image := $images }}
{{ if gt $index 0 }}
{{ $pageNum := math.Add $index 1 }}
{{ $nextPage := "" }}
{{ $lastPage := "" }}
{{ if lt $pageNum $imageCount }}
{{ $nextPage = printf "../%d/" (math.Add $pageNum 1) }}
{{ $lastPage = printf "../%d/" $imageCount }}
{{ end }}
{{ $prevPage := "../" }}
{{ if gt $pageNum 2 }}
{{ $prevPage = printf "../%d/" $index }}
{{ end }}
{{ $page := dict
"path" (printf "%s/%d" $comicDir $pageNum)
"title" (printf "%s, Seite %d" $comicData.title $pageNum)
"description" $comicData.description
"params" (dict
"image" $image
"next" $nextPage
"prev" $prevPage
"last" $lastPage
)
}}
{{ $.AddPage $page }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}