diff options
| author | rtk0c <[email protected]> | 2025-09-01 11:27:12 -0700 |
|---|---|---|
| committer | rtk0c <[email protected]> | 2025-09-01 11:27:12 -0700 |
| commit | 568d2f599f7f42494758797f0d052f3a2847cbf0 (patch) | |
| tree | c16ace68524dc3c554f83f7501cc9acf255ac0f4 /themes/PaperMod/layouts/partials/cover.html | |
| parent | cb3897c9f07769a820a4fea23946a78fea6456cb (diff) | |
| parent | 86b0d0c422e34c38837b5b5495ad6d295d0e73d2 (diff) | |
Merge commit '86b0d0c422e34c38837b5b5495ad6d295d0e73d2' as 'themes/PaperMod'
Diffstat (limited to 'themes/PaperMod/layouts/partials/cover.html')
| -rw-r--r-- | themes/PaperMod/layouts/partials/cover.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/themes/PaperMod/layouts/partials/cover.html b/themes/PaperMod/layouts/partials/cover.html new file mode 100644 index 0000000..9c1f9ea --- /dev/null +++ b/themes/PaperMod/layouts/partials/cover.html @@ -0,0 +1,65 @@ +{{- with .cxt}} {{/* Apply proper context from dict */}} +{{- if (and .Params.cover.image (not $.isHidden)) }} +<figure class="entry-cover"> + {{- $loading := cond $.IsSingle "eager" "lazy" }} + {{- $addLink := (and site.Params.cover.linkFullImages $.IsSingle) }} + {{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }} + {{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }} + {{- $responsiveImages := (.Params.cover.responsiveImages | default site.Params.cover.responsiveImages) | default true }} + + {{- $pageBundleCover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} + {{- $globalResourcesCover := (resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} + {{- $cover := (or $pageBundleCover $globalResourcesCover)}} + {{- /* We are not using the .Param.cover.relative to decide the location of image */}} + {{- /* If we have the image in pageBundle or globalResources we can process the image */}} + + {{- $sizes := (slice "360" "480" "720" "1080" "1500") }} + {{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}} + {{- if hugo.IsExtended -}} + {{- $processableFormats = $processableFormats | append "webp" -}} + {{- end -}} + + {{- $imgdl := (.Params.cover.image) | absURL }} + {{- if $cover -}} + {{- $imgdl = $cover.Permalink }} + {{- end -}} + + {{- if $addLink }} + <a href="{{ $imgdl }}" target="_blank" rel="noopener noreferrer"> + {{- end }} + + {{- if $cover -}} + {{/* i.e it is present in page bundle */}} + {{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }} + <img loading="{{$loading}}" + srcset='{{- range $size := $sizes -}} + {{- if (ge $cover.Width $size) }} + {{- printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw," $size) }} + {{- end }} + {{- end }} + {{- printf "%s %dw" ($cover.Permalink) ($cover.Width) }}' + src="{{ $cover.Permalink }}" + sizes="(min-width: 768px) 720px, 100vw" + width="{{ $cover.Width }}" height="{{ $cover.Height }}" + alt="{{ $alt }}"> + {{- else }}{{/* Unprocessable image or responsive images disabled */}} + <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> + {{- end }} + {{- else }} + {{- /* For absolute urls and external links, no img processing here */}} + <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> + {{- end }} + + {{- if $addLink }} + </a> + {{- end -}} + + {{- /* Display Caption */}} + {{- if $.IsSingle }} + {{ with .Params.cover.caption -}} + <figcaption>{{ . | markdownify }}</figcaption> + {{- end }} + {{- end }} +</figure> +{{- end }}{{/* End image */}} +{{- end -}}{{/* End context */ -}} |
