bunteshaus.de/themes/buha/layouts/partials/snippets/banner.html

122 lines
5.2 KiB
HTML
Raw Normal View History

2022-05-06 11:49:30 +02:00
{{ $title := .Title }}
{{ $title = singularize $title }}
{{ $title = i18n $title }}
{{ if not $title }}
{{ $title = .Title }}
{{ end }}
2022-06-12 19:27:57 +02:00
{{ $good_w := "1920"}}
{{ $good_h := "550"}}
2022-05-09 23:17:23 +02:00
{{ $px := string "400" }}
{{ $fill := string (printf "1280x%s smart" $px) }}
2022-05-06 13:29:00 +02:00
{{ $what := "none" }}
{{ $img := "none" }}
{{ if eq .Kind "home" }}
{{ $what = "home" }}
2022-05-06 14:01:05 +02:00
{{ else }}
{{ with .File }}
{{ $what = .File.ContentBaseName }}
{{ end }}
2022-05-06 13:29:00 +02:00
{{ end }}
{{ $banner := printf "/images/banner/%s*" $what }}
{{ if resources.GetMatch $banner }}
2022-05-09 23:17:23 +02:00
{{ $img = (resources.GetMatch $banner).Fill $fill }}
2022-05-06 13:29:00 +02:00
{{ end }}
2022-05-09 21:37:34 +02:00
{{ if and (resources.GetMatch $banner) (ne .Params.banner false) }}
2022-06-08 00:38:13 +02:00
<div style="background-image: url({{- $img.Permalink -}})" class="banner">
2022-06-12 17:24:42 +02:00
<h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
2022-06-12 18:05:10 +02:00
<div>
2022-06-12 19:27:57 +02:00
{{ $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 }}
2022-06-07 20:15:31 +02:00
</div>
{{ end }}
</div>
2022-05-09 21:37:34 +02:00
{{ else if and (.Resources.Match "banner*") (ne .Params.banner false) }}
2022-05-09 23:17:23 +02:00
{{ $img = (.Resources.GetMatch "banner*").Fill $fill }}
2022-06-12 17:24:42 +02:00
<div style="background-image:url({{- $img.Permalink -}})" class="banner">
<h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
2022-06-12 18:05:10 +02:00
<div>
2022-06-12 19:27:57 +02:00
{{ $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 }}
2022-06-12 17:24:42 +02:00
</div>
{{ end }}
2022-06-07 20:15:31 +02:00
</div>
2022-06-12 19:27:57 +02:00
{{ else if and (.Resources.ByType "image") (ne .Params.banner false) }}
2022-05-09 23:17:23 +02:00
{{ $img = (index (.Resources.ByType "image") 0).Fill $fill }}
2022-06-12 17:24:42 +02:00
<div style="background-image: url({{- $img.Permalink -}})" class="banner">
<h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
2022-06-12 18:05:10 +02:00
<div>
2022-06-12 19:27:57 +02:00
{{ $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 }}
2022-06-12 17:24:42 +02:00
</div>
{{ end }}
2022-06-07 20:15:31 +02:00
</div>
2022-05-06 13:29:00 +02:00
{{ else }}
2022-06-12 17:24:42 +02:00
<div class="banner">
<h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
2022-06-12 19:27:57 +02:00
<p>
assets/images/banner/{{ $what -}}.* missing..<br>
or<br>
{{ with .File }}content/{{ .Dir }}/banner* missing..{{ end }}
</p>
2022-06-12 17:24:42 +02:00
{{ end }}
</div>
2022-05-06 11:49:30 +02:00
{{ end }}