Skip to content

Commit 4461401

Browse files
committed
fix(layouts): Ensure consistent featured image rendering
Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 2c98838 commit 4461401

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

archetypes/default.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ categories: []
1818
hiddenFromHomePage: false
1919
hiddenFromSearch: false
2020

21-
featuredImage: ""
22-
featuredImagePreview: ""
21+
# Direct image path (string)
22+
# featuredImage: ""
23+
# featuredImagePreview: ""
24+
# Hugo Page Bundle resource (object), recommended for advanced image processing.
25+
resources:
26+
- name: "featured-image"
27+
src: ""
28+
- name: "featured-image-preview"
29+
src: ""
2330

2431
toc:
2532
enable: true

layouts/posts/single.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ <h2 class="toc-title">{{ T "contents" }}</h2>
2222

2323
{{- /* Featured image */ -}}
2424
{{- $image := "" -}}
25-
{{- with .Params.featuredimage -}}
25+
{{- with .Params.featuredimage | default .Params.featuredImage -}}
2626
{{- $image = . | relURL -}}
2727
{{- else -}}
28-
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
29-
{{- with $imageResource -}}
28+
{{- with .Resources.GetMatch "featured-image" -}}
3029
{{- $image = .RelPermalink -}}
3130
{{- else -}}
3231
{{- range .Params.resources -}}
33-
{{- if eq .name "featured-image" -}}
34-
{{- $image = .src | relURL -}}
35-
{{- end -}}
32+
{{- if eq .name "featured-image" -}}{{- $image = .src | relURL -}}{{- end -}}
3633
{{- end -}}
3734
{{- end -}}
3835
{{- end -}}

layouts/section.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ <h3 class="group-title">{{ .Key }}</h3>
2323
<div class="timeline">
2424
<div class="circle">
2525
{{- $image := "" -}}
26-
{{- with .Params.featuredimage -}}
26+
{{- with .Params.featuredimagepreview | default .Params.featuredImagePreview -}}
2727
{{- $image = . | relURL -}}
2828
{{- else -}}
29-
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
30-
{{- with $imageResource -}}
29+
{{- with .Resources.GetMatch "featured-image-preview" -}}
3130
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
3231
{{- else -}}
3332
{{- range .Params.resources -}}
34-
{{- if eq .name "featured-image" -}}
35-
{{- $image = .src | relURL -}}
33+
{{- if eq .name "featured-image-preview" -}}{{- $image = .src | relURL -}}{{- end -}}
34+
{{- end -}}
35+
{{- end -}}
36+
{{- end -}}
37+
{{- if not $image -}}
38+
{{- with .Params.featuredimage | default .Params.featuredImage -}}
39+
{{- $image = . | relURL -}}
40+
{{- else -}}
41+
{{- with .Resources.GetMatch "featured-image" -}}
42+
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
43+
{{- else -}}
44+
{{- range .Params.resources -}}
45+
{{- if eq .name "featured-image" -}}{{- $image = .src | relURL -}}{{- end -}}
3646
{{- end -}}
3747
{{- end -}}
3848
{{- end -}}

layouts/summary.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,32 @@
77
{{- /* Featured image */ -}}
88
{{- if .Site.Params.home.posts.imagePreview -}}
99
{{- $image := "" -}}
10-
{{- with .Params.featuredimagepreview -}}
10+
{{- with .Params.featuredimagepreview | default .Params.featuredImagePreview -}}
1111
{{- $image = . | relURL -}}
1212
{{- else -}}
13-
{{- with .Params.featuredimage -}}
13+
{{- with .Resources.GetMatch "featured-image-preview" -}}
14+
{{- $image = .RelPermalink -}}
15+
{{- else -}}
16+
{{- range .Params.resources -}}
17+
{{- if eq .name "featured-image-preview" -}}{{- $image = .src | relURL -}}{{- end -}}
18+
{{- end -}}
19+
{{- end -}}
20+
{{- end -}}
21+
22+
{{- if not $image -}}
23+
{{- with .Params.featuredimage | default .Params.featuredImage -}}
1424
{{- $image = . | relURL -}}
1525
{{- else -}}
16-
{{- $imageResource := .Resources.GetMatch "featured-image-preview" | default (.Resources.GetMatch "featured-image") -}}
17-
{{- with $imageResource -}}
26+
{{- with .Resources.GetMatch "featured-image" -}}
1827
{{- $image = .RelPermalink -}}
1928
{{- else -}}
2029
{{- range .Params.resources -}}
21-
{{- if or (eq .name "featured-image-preview") (eq .name "featured-image") -}}
22-
{{- $image = .src | relURL -}}
23-
{{- end -}}
30+
{{- if eq .name "featured-image" -}}{{- $image = .src | relURL -}}{{- end -}}
2431
{{- end -}}
2532
{{- end -}}
2633
{{- end -}}
2734
{{- end -}}
35+
2836
{{- with $image -}}
2937
<div class="featured-image-preview">
3038
<a href="{{ $.RelPermalink }}">

layouts/term.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@ <h3 class="group-title">{{ .Key }}</h3>
3030
<div class="timeline">
3131
<div class="circle">
3232
{{- $image := "" -}}
33-
{{- with .Params.featuredimage -}}
33+
{{- with .Params.featuredimagepreview | default .Params.featuredImagePreview -}}
3434
{{- $image = . | relURL -}}
3535
{{- else -}}
36-
{{- $imageResource := .Resources.GetMatch "featured-image" -}}
37-
{{- with $imageResource -}}
36+
{{- with .Resources.GetMatch "featured-image-preview" -}}
3837
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
3938
{{- else -}}
4039
{{- range .Params.resources -}}
41-
{{- if eq .name "featured-image" -}}
42-
{{- $image = .src | relURL -}}
40+
{{- if eq .name "featured-image-preview" -}}{{- $image = .src | relURL -}}{{- end -}}
41+
{{- end -}}
42+
{{- end -}}
43+
{{- end -}}
44+
{{- if not $image -}}
45+
{{- with .Params.featuredimage | default .Params.featuredImage -}}
46+
{{- $image = . | relURL -}}
47+
{{- else -}}
48+
{{- with .Resources.GetMatch "featured-image" -}}
49+
{{- $image = (.Fill "68x68 Center q100 Lanczos").RelPermalink -}}
50+
{{- else -}}
51+
{{- range .Params.resources -}}
52+
{{- if eq .name "featured-image" -}}{{- $image = .src | relURL -}}{{- end -}}
4353
{{- end -}}
4454
{{- end -}}
4555
{{- end -}}

0 commit comments

Comments
 (0)