bunteshaus.de/themes/buha/layouts/partials/snippets/banner.html
2022-06-15 15:46:35 +02:00

144 lines
6.4 KiB
HTML

{{ $title := .Title }}
{{ $title = singularize $title }}
{{ $title = i18n $title }}
{{ if not $title }}
{{ $title = .Title }}
{{ end }}
{{ $good_w := "1920"}}
{{ $good_h := "850"}}
{{ $what := "none" }}
{{ $img := "none" }}
{{ if eq .Kind "home" }}
{{ $what = "home" }}
{{ else if eq .Kind "term" }}
{{ $what = printf "term/%s" (anchorize .Title) }}
{{ else if eq .Kind "taxonomy" }}
{{ $what = .Data.Singular }}
{{ else }}
{{ with .File }}
{{ $what = .File.ContentBaseName }}
{{ end }}
{{ end }}
{{ $title_class := safeCSS "title" }}
{{ $css := safeCSS "b" }}
{{ if .IsHome }}
{{ $css = safeCSS "b_index" }}
{{ $title_class = safeCSS "title_index" }}
{{ end }}
{{ $banner := string (printf "/images/banner/%s*" $what) }}
{{ if resources.GetMatch $banner }}
{{ $img = resources.GetMatch $banner }}
{{ end }}
{{ $single := false }}
{{ if and (in .File "news/") (not (in .File "_index"))}}
{{ $single = true }}
{{ end }}
{{ if and (ne $img "none") (ne .Params.banner false) }}
<div style="background-image: url({{- $img.Permalink -}})" class="banner {{ $css }}">
{{ if eq hugo.Environment "development" }}
<div style="color: red; background: white;">
{{ $w := (resources.GetMatch $banner).Width }}
{{ $h := (resources.GetMatch $banner).Height }}
{{ if lt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too small, better {{ $good_w -}}px in width<br>
{{ end }}
{{ else if gt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too big, better {{ $good_w -}}px in width<br>
{{ end }}
{{ end }}
{{ if lt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too small, better {{ $good_h -}}px in height<br>
{{ end }}
{{ else if gt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too big, better {{ $good_h -}}px in height<br>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ if not .IsHome }}<h1 class="{{ $title_class }}">{{ $title }}</h1> {{ end }}
</div>
{{ else if and (.Resources.Match "banner*") (ne .Params.banner false) }}
{{ $img = .Resources.GetMatch "banner*" }}
<div style="background-image:url({{- $img.Permalink -}})" class="banner {{ $css }}">
{{ if eq hugo.Environment "development" }}
<div style="color: red; background: white;">
{{ $w := (index (.Resources.Match "banner*") 0).Width }}
{{ $h := (index (.Resources.Match "banner*") 0).Height }}
{{ if lt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too small, better {{ $good_w -}}px in width<br>
{{ end }}
{{ else if gt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too big, better {{ $good_w -}}px in width<br>
{{ end }}
{{ end }}
{{ if lt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too small, better {{ $good_h -}}px in height<br>
{{ end }}
{{ else if gt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too big, better {{ $good_h -}}px in height<br>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ if not .IsHome }}<h1 class="{{ $title_class }}">{{ $title }}</h1> {{ end }}
</div>
{{ else if and (.Resources.ByType "image") (ne .Params.banner false) (not true) }}
{{ $img = index (.Resources.ByType "image") 0 }}
<div style="background-image: url({{- $img.Permalink -}})" class="banner {{ $css }}">
{{ if eq hugo.Environment "development" }}
<div style="color: red; background: white;">
{{ $w := (index (.Resources.ByType "image") 0).Width }}
{{ $h := (index (.Resources.ByType "image") 0).Height }}
{{ if lt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too small, better {{ $good_w -}}px in width<br>
{{ end }}
{{ else if gt (int $w) $good_w }}
{{ if eq hugo.Environment "development" }}
Width: {{ $w }}px: too big, better {{ $good_w -}}px in width<br>
{{ end }}
{{ end }}
{{ if lt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too small, better {{ $good_h -}}px in height<br>
{{ end }}
{{ else if gt (int $h) $good_h }}
{{ if eq hugo.Environment "development" }}
Height: {{ $h }}px: too big, better {{ $good_h -}}px in height<br>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ if not .IsHome }}<h1 class="{{ $title_class }}">{{ $title }}</h1> {{ end }}
</div>
{{ else }}
<div class="banner b altbg">
{{ if eq hugo.Environment "development" }}
{{ if eq .Params.banner false }}
<div style="color: black; background: white;">
Info: Banner is turned off for this.
{{ else }}
<div style="color: red; background: white;">
{{ if eq $single true }}
{{ with .File }}
{{ printf "content/%sbanner* missing.." .Dir }}
{{ end }}
{{ else if eq $single false }}
{{ printf "assets/images/banner/%s* missing.." $what }}
{{ end }}
{{ end }}
</div>
{{ end }}
{{ if not .IsHome }}<h1 class="{{ $title_class }}">{{ $title }}</h1> {{ end }}
</div>
{{ end }}