backgrounds and feature images support svg

This commit is contained in:
Nuno Coração
2024-03-09 23:44:14 +00:00
parent b490f97b8b
commit 8bbd8b8626
11 changed files with 91 additions and 15 deletions

View File

@@ -19,7 +19,7 @@
{{ end }}
{{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
{{ with . }}
<div class="w-full thumbnail_card_related nozoom" style="background-image:url({{ .RelPermalink }});"></div>
{{ end }}

View File

@@ -20,7 +20,7 @@
{{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}}
{{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
{{ with . }}
<div class="w-full thumbnail_card nozoom" style="background-image:url({{ .RelPermalink }});"></div>
{{ end }}

View File

@@ -47,7 +47,7 @@
{{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}}
{{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
{{ with . }}
<div class="{{ $articleImageClasses }}" style="background-image:url({{ .RelPermalink }});"></div>
{{ end }}

View File

@@ -30,10 +30,12 @@
(and ($.Site.Params.list.layoutBackgroundHeaderSpace | default true) ($isParentList))
) }}
{{- with $featured -}}
{{ if $shouldAddHeaderSpace | default true}}
<div id="hero" class="h-[150px] md:h-[200px]"></div>
{{ end }}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
{{ with . }}
<div class="fixed inset-x-0 top-0 h-[800px] single_hero_background nozoom"
style="background-image:url({{ .RelPermalink }});">

View File

@@ -1,14 +1,27 @@
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
{{- $images := .Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- $featured := $images.GetMatch "*background*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{ if .Params.featureimage }}
{{ if and .Params.featureimage (not $featured) }}
{{- $url:= .Params.featureimage -}}
{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}}
{{ $featured = resources.GetRemote $url }}
{{ end }}
{{- if not $featured }}
{{ with .Site.Params.defaultBackgroundImage }}
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
{{ $featured = resources.GetRemote . }}
{{ else }}
{{ $featured = resources.Get . }}
{{ end }}
{{ end }}
{{ end -}}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
{{ with . }}
<div class="w-full h-36 md:h-56 lg:h-72 single_hero_basic nozoom" style="background-image:url({{ .RelPermalink }});"></div>
{{ end }}

View File

@@ -1,18 +1,44 @@
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
{{- $images := .Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- $featured := $images.GetMatch "*background*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{ $caption := "" }}
{{ if .Params.featureimage }}
{{- $url:= .Params.featureimage -}}
{{- $caption = .Params.featureimagecaption -}}
{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}}
{{ end }}
{{- if not $featured }}
{{ with .Site.Params.defaultBackgroundImage }}
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
{{ $featured = resources.GetRemote . }}
{{ else }}
{{ $featured = resources.Get . }}
{{ end }}
{{ end }}
{{ end -}}
{{ $caption := "" }}
{{ if .Params.featureimagecaption }}
{{- $caption = .Params.featureimagecaption -}}
{{ end }}
{{- $alt := .Page.Title -}}
{{- with .Page.Params.alt }}{{ $alt = . }}{{ end -}}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if strings.HasSuffix $featured ".svg" }}
{{ with . }}
<figure>
<img class="w-full rounded-lg single_hero_round nozoom" alt="{{ $alt }}" src="{{ .RelPermalink }}">
{{ if $caption }}
<figcaption class="text-sm text-neutral-700 dark:text-neutral-400 hover:underline" style="text-align: center;"> {{ $caption | markdownify }} </figcaption>
{{end}}
</figure>
{{ end }}
{{ else if $disableImageOptimization }}
{{ with . }}
<figure>
<img class="w-full rounded-lg single_hero_round nozoom" alt="{{ $alt }}" width="{{ .Width }}" height="{{ .Height }}" src="{{ .RelPermalink }}">

View File

@@ -20,7 +20,7 @@
) }}
{{- with $featured -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix . ".svg")}}
{{ with . }}
<div class="w-full rounded-md h-36 md:h-56 lg:h-72 single_hero_basic nozoom" style="background-image:url({{ .RelPermalink }});"></div>
{{ end }}
@@ -33,7 +33,7 @@
{{- with $background -}}
{{ if $disableImageOptimization }}
{{ if or $disableImageOptimization (strings.HasSuffix . ".svg")}}
{{ with . }}
<div class="fixed inset-x-0 top-0 h-[800px] single_hero_background nozoom"
style="background-image:url({{ .RelPermalink }});">