Skip to content

Commit 2c98838

Browse files
committed
fix(layouts): Correct featured-image path handling
Resolves an issue where `featured-image` paths pointing to assets outside a page bundle were not being correctly loaded. This was particularly evident when using the `resources` front matter parameter with an absolute `src` path. Fixes #142 Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 304fc9c commit 2c98838

File tree

4 files changed

+68
-19
lines changed

4 files changed

+68
-19
lines changed

layouts/posts/single.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@ <h2 class="toc-title">{{ T "contents" }}</h2>
2121
<article class="page single" data-toc="{{ if ne $toc.enable true }}disable{{ else }}enable{{ end }}">
2222

2323
{{- /* Featured image */ -}}
24-
{{- $image := $params.featuredimage -}}
25-
{{- with .Resources.GetMatch "featured-image" -}}
26-
{{- $image = .RelPermalink -}}
24+
{{- $image := "" -}}
25+
{{- with .Params.featuredimage -}}
26+
{{- $image = . | relURL -}}
27+
{{- else -}}
28+
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
29+
{{- with $imageResource -}}
30+
{{- $image = .RelPermalink -}}
31+
{{- else -}}
32+
{{- range .Params.resources -}}
33+
{{- if eq .name "featured-image" -}}
34+
{{- $image = .src | relURL -}}
35+
{{- end -}}
36+
{{- end -}}
37+
{{- end -}}
2738
{{- end -}}
2839
{{- with $image -}}
2940
<div class="featured-image">
30-
{{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}}
41+
{{- dict "Src" . "Title" $.Description | partial "plugin/image.html" -}}
3142
</div>
3243
{{- end -}}
3344

layouts/section.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@ <h3 class="group-title">{{ .Key }}</h3>
2222
{{- range .Pages -}}
2323
<div class="timeline">
2424
<div class="circle">
25-
{{- $featured := .Resources.Get "featured-image" -}}
25+
{{- $image := "" -}}
26+
{{- with .Params.featuredimage -}}
27+
{{- $image = . | relURL -}}
28+
{{- else -}}
29+
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
30+
{{- with $imageResource -}}
31+
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
32+
{{- else -}}
33+
{{- range .Params.resources -}}
34+
{{- if eq .name "featured-image" -}}
35+
{{- $image = .src | relURL -}}
36+
{{- end -}}
37+
{{- end -}}
38+
{{- end -}}
39+
{{- end -}}
2640
<a href="{{ .RelPermalink }}" class="item-link-wrapper">
2741
<div class="item-with-image">
28-
{{- if $featured -}}
29-
{{- $image := $featured.Fill "68x68 Center q100 Lanczos" -}}
42+
{{- if $image -}}
3043
<div class="item-image">
31-
{{- dict "Src" $image.RelPermalink "Title" .Title "Loading" "lazy" | partial "plugin/image.html" -}}
44+
{{- dict "Src" $image "Title" .Title "Loading" "lazy" | partial "plugin/image.html" -}}
3245
</div>
3346
{{- else -}}
3447
<div class="item-image-placeholder">

layouts/summary.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@
66
{{- end -}}
77
{{- /* Featured image */ -}}
88
{{- if .Site.Params.home.posts.imagePreview -}}
9-
{{- $image := $params.featuredimagepreview | default $params.featuredimage -}}
10-
{{- with .Resources.GetMatch "featured-image" -}}
11-
{{- $image = .RelPermalink -}}
12-
{{- end -}}
13-
{{- with .Resources.GetMatch "featured-image-preview" -}}
14-
{{- $image = .RelPermalink -}}
9+
{{- $image := "" -}}
10+
{{- with .Params.featuredimagepreview -}}
11+
{{- $image = . | relURL -}}
12+
{{- else -}}
13+
{{- with .Params.featuredimage -}}
14+
{{- $image = . | relURL -}}
15+
{{- else -}}
16+
{{- $imageResource := .Resources.GetMatch "featured-image-preview" | default (.Resources.GetMatch "featured-image") -}}
17+
{{- with $imageResource -}}
18+
{{- $image = .RelPermalink -}}
19+
{{- else -}}
20+
{{- range .Params.resources -}}
21+
{{- if or (eq .name "featured-image-preview") (eq .name "featured-image") -}}
22+
{{- $image = .src | relURL -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
{{- end -}}
1527
{{- end -}}
1628
{{- with $image -}}
1729
<div class="featured-image-preview">
1830
<a href="{{ $.RelPermalink }}">
19-
{{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}}
31+
{{- dict "Src" . "Title" $.Description | partial "plugin/image.html" -}}
2032
</a>
2133
</div>
2234
{{- else -}}

layouts/term.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@ <h3 class="group-title">{{ .Key }}</h3>
2929
{{- range .Pages -}}
3030
<div class="timeline">
3131
<div class="circle">
32-
{{- $featured := .Resources.Get "featured-image" -}}
32+
{{- $image := "" -}}
33+
{{- with .Params.featuredimage -}}
34+
{{- $image = . | relURL -}}
35+
{{- else -}}
36+
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
37+
{{- with $imageResource -}}
38+
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
39+
{{- else -}}
40+
{{- range .Params.resources -}}
41+
{{- if eq .name "featured-image" -}}
42+
{{- $image = .src | relURL -}}
43+
{{- end -}}
44+
{{- end -}}
45+
{{- end -}}
46+
{{- end -}}
3347
<a href="{{ .RelPermalink }}" class="item-link-wrapper">
3448
<div class="item-with-image">
35-
{{- if $featured -}}
36-
{{- $image := $featured.Fill "68x68 Center q100 Lanczos" -}}
49+
{{- if $image -}}
3750
<div class="item-image">
38-
{{- dict "Src" $image.RelPermalink "Title" .Title "Loading" "lazy" | partial "plugin/image.html" -}}
51+
{{- dict "Src" $image "Title" .Title "Loading" "lazy" | partial "plugin/image.html" -}}
3952
</div>
4053
{{- else -}}
4154
<div class="item-image-placeholder">

0 commit comments

Comments
 (0)