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

64 lines
3.2 KiB
HTML

{{ $title := .Title }}
{{ $title = singularize $title }}
{{ $title = i18n $title }}
{{ if not $title }}
{{ $title = .Title }}
{{ end }}
{{ $px := string "400" }}
{{ $fill := string (printf "1280x%s smart" $px) }}
{{ $all := "" }}
{{ $style := safeCSS "text-shadow: 0px 3px 0px #b2a98f, 0px 14px 10px rgba(0,0,0,0.15), 0px 24px 2px rgba(0,0,0,0.1), 0px 34px 30px rgba(0,0,0,0.1)" }}
{{ $what := "none" }}
{{ $img := "none" }}
{{ if eq .Kind "home" }}
{{ $what = "home" }}
{{ else }}
{{ with .File }}
{{ $what = .File.ContentBaseName }}
{{ end }}
{{ end }}
{{ $banner := printf "/images/banner/%s*" $what }}
{{ if resources.GetMatch $banner }}
{{ $img = (resources.GetMatch $banner).Fill $fill }}
{{ end }}
{{ $height := safeCSS (printf "min-height: calc(%spx - 5rem); max-height: calc(%spx - 5rem);" $px $px) }}
{{ if and (resources.GetMatch $banner) (ne .Params.banner false) }}
{{ $height = safeCSS (printf "height: calc(%spx - 5rem);" (string $img.Height)) }}
<div style="background-image: url({{- $img.Permalink -}})" class="banner banner-shadow center_bg_img">
<h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
<div style="display: flex; flex-direction: column;">
<div>Width: {{ (resources.GetMatch $banner).Width }}px</div>
<div>Height: {{ (resources.GetMatch $banner).Height }}px</div>
<div>Ratio: {{div (float (resources.GetMatch $banner).Width) (float (resources.GetMatch $banner).Height) }}</div>
</div>
{{ end }}
</div>
{{ else if and (.Resources.Match "banner*") (ne .Params.banner false) }}
{{ $img = (.Resources.GetMatch "banner*").Fill $fill }}
{{ $height = safeCSS (printf "height: calc(%spx - 5rem);" (string $img.Height)) }}
<div style="background-image:url({{- $img.Permalink -}})" class="banner banner-shadow center_bg_img"><h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
<div style="display: flex; flex-direction: column;">
<div>Width: {{ (index (.Resources.Match "banner*") 0).Width }}px</div>
<div>Height: {{ (index (.Resources.Match "banner*") 0).Height }}px</div>
<div>Ratio: {{div (float (index (.Resources.Match "banner*") 0).Width) (float (index (.Resources.Match "banner*") 0).Height) }}</div>
</div>
{{ end }}
</div>
{{ else if and (.Resources.ByType "image") (ne .Params.banner false) $all }}
{{ $img = (index (.Resources.ByType "image") 0).Fill $fill }}
{{ $height = safeCSS (printf "height: calc(%spx - 5rem);" (string $img.Height)) }}
<div style="background-image: url({{- $img.Permalink -}})" class="banner banner-shadow center_bg_img"><h1>{{ $title }}</h1>
{{ if eq hugo.Environment "development" }}
<div style="display: flex; flex-direction: column;">
<div>Width: {{ (index (.Resources.ByType "image") 0).Width }}px</div>
<div>Height: {{ (index (.Resources.ByType "image") 0).Height }}px</div>
<div>Ratio: {{div (float (index (.Resources.ByType "image") 0).Width) (float (index (.Resources.ByType "image") 0).Height) }}</div>
</div>
{{ end }}
</div>
{{ else }}
<div class="banner"><h1>{{ $title }}</h1></div>
{{ end }}