mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-14 00:16:31 +00:00
feat: safely parse image front matter structure
This commit is contained in:
1 parent
3b9130e042
commit
c48b65edb2
4 files changed
+30
-14
No files matched your search
@@ -13,7 +13,10 @@
|
||||
{{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }}
|
||||
{{ if eq $resource nil }}
|
||||
{{/* Otherwise fall back the image file specified in front matter */}}
|
||||
{{ $filename := .Params.image.filename }}
|
||||
{{ $filename := "" }}
|
||||
{{ if and .Params.image (reflect.IsMap .Params.image) }}
|
||||
{{ $filename = .Params.image.filename }}
|
||||
{{ end }}
|
||||
{{/* Search in page folder */}}
|
||||
{{ $resource = (.Resources.ByType "image").GetMatch $filename }}
|
||||
{{/* Otherwise in `assets/media/` folder */}}
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
{{ end }}
|
||||
|
||||
{{ $resource := partial "functions/get_featured_image.html" $item }}
|
||||
{{ $anchor := $item.Params.image.focal_point | default "Center" }}
|
||||
{{ $anchor := "Center" }}
|
||||
{{ if and $item.Params.image (reflect.IsMap $item.Params.image) }}
|
||||
{{ $anchor = $item.Params.image.focal_point | default "Center" }}
|
||||
{{ end }}
|
||||
{{ $fill_image := .config.fill_image | default true }}
|
||||
{{ $showDate := .config.show_date | default true }}
|
||||
{{ $showReadTime := .config.show_read_time | default true }}
|
||||
|
||||
@@ -251,12 +251,17 @@
|
||||
{{ else }}
|
||||
{{/* Fallback to featured image if no slides */}}
|
||||
{{ $featured := partial "functions/get_featured_image.html" . }}
|
||||
{{ if and $featured (not .Params.image.preview_only) }}
|
||||
{{/* Safely extract image parameters - handle case where image is not a map */}}
|
||||
{{ $image_params := dict }}
|
||||
{{ if and .Params.image (reflect.IsMap .Params.image) }}
|
||||
{{ $image_params = .Params.image }}
|
||||
{{ end }}
|
||||
{{ if and $featured (not $image_params.preview_only) }}
|
||||
{{/* Fit image within max size. */}}
|
||||
{{ $image := $featured }}
|
||||
|
||||
{{/* Determine image placement. */}}
|
||||
{{ $placement := .Params.image.placement | default 1 }}{{/* Default to full column width. */}}
|
||||
{{ $placement := $image_params.placement | default 1 }}{{/* Default to full column width. */}}
|
||||
{{/* Configure responsive processing based on placement */}}
|
||||
{{ $image_container := "" }}
|
||||
{{ $responsive_sizes := slice }}
|
||||
@@ -301,10 +306,10 @@
|
||||
src="{{ $responsive.fallback.RelPermalink }}"
|
||||
width="{{ $fitted_image.Width }}"
|
||||
height="{{ $fitted_image.Height }}"
|
||||
alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}"
|
||||
alt="{{ with $image_params.alt_text }}{{.}}{{ end }}"
|
||||
class="featured-image"
|
||||
fetchpriority="high">
|
||||
{{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
{{ with $image_params.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
@@ -322,10 +327,10 @@
|
||||
<img src="{{ $image.RelPermalink }}"
|
||||
width="{{ $image.Width }}"
|
||||
height="{{ $image.Height }}"
|
||||
alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}"
|
||||
alt="{{ with $image_params.alt_text }}{{.}}{{ end }}"
|
||||
class="featured-image"
|
||||
fetchpriority="high">
|
||||
{{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
{{ with $image_params.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
@@ -147,13 +147,18 @@
|
||||
|
||||
|
||||
{{ $featured := partial "functions/get_featured_image.html" . }}
|
||||
{{/* Safely extract image parameters - handle case where image is not a map */}}
|
||||
{{ $image_params := dict }}
|
||||
{{ if and .Params.image (reflect.IsMap .Params.image) }}
|
||||
{{ $image_params = .Params.image }}
|
||||
{{ end }}
|
||||
{{/* Featured image layout */}}
|
||||
{{ if and $featured (not .Params.image.preview_only) }}
|
||||
{{ if and $featured (not $image_params.preview_only) }}
|
||||
{{/* Fit image within max size. */}}
|
||||
{{ $image := $featured }}
|
||||
|
||||
{{/* Determine image placement. */}}
|
||||
{{ $placement := .Params.image.placement | default 1 }}{{/* Default to full column width. */}}
|
||||
{{ $placement := $image_params.placement | default 1 }}{{/* Default to full column width. */}}
|
||||
{{/* Configure responsive processing based on placement */}}
|
||||
{{ $image_container := "" }}
|
||||
{{ $responsive_sizes := slice }}
|
||||
@@ -198,10 +203,10 @@
|
||||
src="{{ $responsive.fallback.RelPermalink }}"
|
||||
width="{{ $fitted_image.Width }}"
|
||||
height="{{ $fitted_image.Height }}"
|
||||
alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}"
|
||||
alt="{{ with $image_params.alt_text }}{{.}}{{ end }}"
|
||||
class="featured-image"
|
||||
fetchpriority="high">
|
||||
{{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
{{ with $image_params.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
@@ -219,10 +224,10 @@
|
||||
<img src="{{ $image.RelPermalink }}"
|
||||
width="{{ $image.Width }}"
|
||||
height="{{ $image.Height }}"
|
||||
alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}"
|
||||
alt="{{ with $image_params.alt_text }}{{.}}{{ end }}"
|
||||
class="featured-image"
|
||||
fetchpriority="high">
|
||||
{{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
{{ with $image_params.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
Reference in new issue
Block a user