mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
feat(hero): add support for hotlinkFeatureImages
This commit is contained in:
@@ -1,28 +1,42 @@
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
{{ $disableImageOptimization := site.Store.Get "disableImageOptimization" }}
|
||||
|
||||
{{ $featured := "" }}
|
||||
{{ if .Params.featureimage }}
|
||||
{{ $url := .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ $featuredURL := "" }}
|
||||
{{ with .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ if site.Params.hotlinkFeatureImages }}
|
||||
{{ $featuredURL = . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get $url }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ $images := $.Resources.ByType "image" }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $images := .Resources.ByType "image" }}
|
||||
{{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }}
|
||||
{{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ with .Site.Params.defaultBackgroundImage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $default := site.Store.Get "defaultBackgroundImage" }}
|
||||
{{ if $default.url }}
|
||||
{{ $featuredURL = $default.url }}
|
||||
{{ else if $default.obj }}
|
||||
{{ $featured = $default.obj }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* generate image URL if not hotlink */}}
|
||||
{{ if not $featuredURL }}
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := site.Store.Get "backgroundImageWidth" }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -39,18 +53,14 @@
|
||||
)
|
||||
}}
|
||||
|
||||
{{- with $featured -}}
|
||||
{{- with $featuredURL -}}
|
||||
{{ if $shouldAddHeaderSpace | default true }}
|
||||
<div id="hero" class="h-[150px] md:h-[200px]"></div>
|
||||
{{ end }}
|
||||
<div class="fixed inset-x-0 top-0 h-[800px] single_hero_background nozoom">
|
||||
{{ $imageURL := .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $imageURL = (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")).RelPermalink }}
|
||||
{{ end }}
|
||||
<img
|
||||
id="background-image"
|
||||
src="{{ $imageURL }}"
|
||||
src="{{ . }}"
|
||||
alt="Background Image"
|
||||
class="absolute inset-0 w-full h-full object-cover">
|
||||
<div
|
||||
@@ -71,6 +81,6 @@
|
||||
integrity="{{ $backgroundBlur.Data.Integrity }}"
|
||||
data-blur-id="background-blur"
|
||||
data-image-id="background-image"
|
||||
data-image-url="{{ .RelPermalink }}"></script>
|
||||
data-image-url="{{ . }}"></script>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
{{ $disableImageOptimization := site.Store.Get "disableImageOptimization" }}
|
||||
|
||||
{{ $featured := "" }}
|
||||
{{ $featuredURL := "" }}
|
||||
{{ if .Params.featureimage }}
|
||||
{{ $url := .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ with .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ if site.Params.hotlinkFeatureImages }}
|
||||
{{ $featuredURL = . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get $url }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ $images := $.Resources.ByType "image" }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $images := .Resources.ByType "image" }}
|
||||
{{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }}
|
||||
{{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }}
|
||||
{{ 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 }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $default := site.Store.Get "defaultBackgroundImage" }}
|
||||
{{ if $default.url }}
|
||||
{{ $featuredURL = $default.url }}
|
||||
{{ else if $default.obj }}
|
||||
{{ $featured = $default.obj }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{/* generate image URL if not hotlink */}}
|
||||
{{ if not $featuredURL }}
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := site.Store.Get "backgroundImageWidth" }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
@@ -1,28 +1,42 @@
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
{{ $disableImageOptimization := site.Store.Get "disableImageOptimization" }}
|
||||
|
||||
{{ $featured := "" }}
|
||||
{{ if .Params.featureimage }}
|
||||
{{ $url := .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ $featuredURL := "" }}
|
||||
{{ with .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ if site.Params.hotlinkFeatureImages }}
|
||||
{{ $featuredURL = . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get $url }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ $images := $.Resources.ByType "image" }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $images := .Resources.ByType "image" }}
|
||||
{{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }}
|
||||
{{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ with .Site.Params.defaultBackgroundImage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $default := site.Store.Get "defaultBackgroundImage" }}
|
||||
{{ if $default.url }}
|
||||
{{ $featuredURL = $default.url }}
|
||||
{{ else if $default.obj }}
|
||||
{{ $featured = $default.obj }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* generate image URL if not hotlink */}}
|
||||
{{ if not $featuredURL }}
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := site.Store.Get "backgroundImageWidth" }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -35,49 +49,13 @@
|
||||
{{- $alt := .Page.Title -}}
|
||||
{{- with .Page.Params.alt }}{{ $alt = . }}{{ end -}}
|
||||
|
||||
{{- with $featured -}}
|
||||
{{ 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 text-center">
|
||||
{{ $caption | markdownify }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
{{ with $featuredURL }}
|
||||
<figure>
|
||||
<img class="w-full rounded-lg single_hero_round nozoom" alt="{{ $alt }}" src="{{ . }}">
|
||||
{{ if $caption }}
|
||||
<figcaption class="text-sm text-neutral-700 dark:text-neutral-400 hover:underline text-center">
|
||||
{{ $caption | markdownify }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
{{ else if $disableImageOptimization }}
|
||||
{{ with . }}
|
||||
<figure>
|
||||
<img
|
||||
class="w-full rounded-lg single_hero_round nozoom"
|
||||
alt="{{ $alt }}"
|
||||
width="{{ .Width }}"
|
||||
height="{{ .Height }}"
|
||||
src="{{ .RelPermalink }}">
|
||||
{{ if $caption }}
|
||||
<figcaption class="text-sm text-neutral-700 dark:text-neutral-400 hover:underline text-center">
|
||||
{{ $caption | markdownify }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
|
||||
<figure>
|
||||
<img
|
||||
class="w-full rounded-lg single_hero_round nozoom"
|
||||
alt="{{ $alt }}"
|
||||
width="{{ .Width }}"
|
||||
height="{{ .Height }}"
|
||||
src="{{ .RelPermalink }}">
|
||||
{{ if $caption }}
|
||||
<figcaption class="text-sm text-neutral-700 dark:text-neutral-400 hover:underline text-center">
|
||||
{{ $caption | markdownify }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</figure>
|
||||
{{ end }}
|
||||
|
||||
@@ -1,64 +1,75 @@
|
||||
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
|
||||
{{ $disableImageOptimization := site.Store.Get "disableImageOptimization" }}
|
||||
|
||||
{{/* === Background === */}}
|
||||
{{ $images := .Resources.ByType "image" }}
|
||||
{{ $background := $images.GetMatch "*background*" }}
|
||||
{{ $backgroundURL := "" }}
|
||||
|
||||
{{ if not $background }}
|
||||
{{ with .Site.Params.defaultBackgroundImage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ $background = resources.GetRemote . }}
|
||||
{{ else }}
|
||||
{{ $background = resources.Get . }}
|
||||
{{ if not (or $background $backgroundURL) }}
|
||||
{{ $default := site.Store.Get "defaultBackgroundImage" }}
|
||||
{{ if $default.url }}
|
||||
{{ $backgroundURL = $default.url }}
|
||||
{{ else if $default.obj }}
|
||||
{{ $background = $default.obj }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not (or $background $backgroundURL) }}
|
||||
{{ range slice "*cover*" "*thumbnail*" "*feature*" }}
|
||||
{{ if not $background }}{{ $background = $images.GetMatch . }}{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* generate image URL if not hotlink */}}
|
||||
{{ if not $backgroundURL }}
|
||||
{{ with $background }}
|
||||
{{ $backgroundURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := site.Store.Get "backgroundImageWidth" }}
|
||||
{{ $backgroundURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ range slice "*cover*" "*thumbnail*" "*feature*" }}
|
||||
{{ if not $background }}{{ $background = $images.GetMatch . }}{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ with $background }}
|
||||
{{ $backgroundURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
|
||||
{{ $backgroundURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* === Featured === */}}
|
||||
{{ $featured := "" }}
|
||||
{{ $featuredURL := "" }}
|
||||
{{ if .Params.featureimage }}
|
||||
{{ $url := .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ with .Params.featureimage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ if site.Params.hotlinkFeatureImages }}
|
||||
{{ $featuredURL = . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get $url }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $images := $.Resources.ByType "image" }}
|
||||
{{ range slice "*feature*" "*cover*" "*thumbnail*" "*background*" }}
|
||||
{{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $featured }}
|
||||
{{ with .Site.Params.defaultFeaturedImage }}
|
||||
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
|
||||
{{ $featured = resources.GetRemote . }}
|
||||
{{ else }}
|
||||
{{ $featured = resources.Get . }}
|
||||
{{ end }}
|
||||
{{ if not (or $featured $featuredURL) }}
|
||||
{{ $default := site.Store.Get "defaultFeaturedImage" }}
|
||||
{{ if $default.url }}
|
||||
{{ $featuredURL = $default.url }}
|
||||
{{ else if $default.obj }}
|
||||
{{ $featured = $default.obj }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{/* generate image URL if not hotlink */}}
|
||||
{{ if not $featuredURL }}
|
||||
{{ with $featured }}
|
||||
{{ $featuredURL = .RelPermalink }}
|
||||
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
|
||||
{{ $size := site.Store.Get "backgroundImageWidth" }}
|
||||
{{ $featuredURL = (.Resize $size).RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
@@ -32,3 +32,6 @@
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ site.Store.Set "defaultBackgroundImage" (dict "url" $defaultBackgroundImageURL "obj" $defaultBackgroundImage) }}
|
||||
|
||||
{{/* backgroundImageWidth */}}
|
||||
{{ site.Store.Set "backgroundImageWidth" (print (site.Params.backgroundImageWidth | default "1200") "x") }}
|
||||
|
||||
Reference in New Issue
Block a user