mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 15:31:52 +00:00
♻️ Refactor: Move inline styles containing background-image: out of line
This greatly reduces the number of inline styles in the project and enhances maintainability by avoiding a lot of duplicate code. This also reduces the number of hashes required for a CSP since all previous background-image inline styles are now in main.css.
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
{{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }}
|
||||
{{ end }}
|
||||
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
|
||||
{{ $articleInnerClasses := "" }}
|
||||
{{ if .Site.Params.list.showCards }}
|
||||
{{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-4") " " }}
|
||||
@@ -37,30 +35,33 @@
|
||||
{{- range first 6 . }}
|
||||
<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
|
||||
{{- else -}}
|
||||
{{- $images := $.Resources.ByType "image" -}}
|
||||
{{- $featured := $images.GetMatch "*feature*" -}}
|
||||
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
|
||||
{{ if and .Params.featureimage (not $featured) }}
|
||||
{{- $url:= .Params.featureimage -}}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ end }}
|
||||
{{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}}
|
||||
{{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }}
|
||||
{{- with $featured -}}
|
||||
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}}
|
||||
{{ with . }}
|
||||
<div class="{{ $articleImageClasses }}" style="background-image:url({{ .RelPermalink }});"></div>
|
||||
{{ end }}
|
||||
{{ $images := $.Resources.ByType "image" }}
|
||||
{{ $featuredImage := $images.GetMatch "*feature*" }}
|
||||
{{ if not $featuredImage }}
|
||||
{{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }}
|
||||
{{ end }}
|
||||
{{ if and (not $featuredImage) .Params.featureimage }}
|
||||
{{ $featuredImage = resources.GetRemote .Params.featureimage }}
|
||||
{{ end }}
|
||||
{{ if not $featuredImage }}
|
||||
{{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }}
|
||||
{{ end }}
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
{{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }}
|
||||
{{ $featuredImage = $featuredImage.Resize "600x" }}
|
||||
{{ end }}
|
||||
{{ if .Params.hideFeatureImage }}
|
||||
{{ $featuredImage = false }}
|
||||
{{ end }}
|
||||
{{ with $featuredImage }}
|
||||
{{ $className := printf "background-image-%s" (md5 .RelPermalink) }}
|
||||
<div class="{{ $articleImageClasses }} {{ $className }}"></div>
|
||||
{{ else }}
|
||||
{{ with .Resize "600x" }}
|
||||
<div class="{{ $articleImageClasses }}" style="background-image:url({{ .RelPermalink }});"></div>
|
||||
{{ with $.Site.Params.images }}
|
||||
<meta property="og:image" content="{{ index . 0 | absURL }}" />
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{- else -}}
|
||||
{{- with $.Site.Params.images }}
|
||||
<meta property="og:image" content="{{ index . 0 | absURL }}" />{{ end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
|
||||
|
||||
<div class="{{ $articleInnerClasses }}">
|
||||
|
||||
Reference in New Issue
Block a user