Skip to content

Commit 98ec749

Browse files
committed
feat: add the post_thumbnail_position parameter
1 parent d64c984 commit 98ec749

File tree

5 files changed

+105
-51
lines changed

5 files changed

+105
-51
lines changed

assets/hb/modules/blog/scss/post/_card.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,39 @@
1717
text-transform: uppercase;
1818
width: 100%;
1919
}
20+
21+
.hb-blog-post-card-wrapper {
22+
.card-img-top {
23+
border: 0 !important;
24+
display: block;
25+
height: 100%;
26+
margin-top: 0 !important;
27+
}
28+
29+
.hb-blog-post-card-img {
30+
@extend .rounded-0;
31+
}
32+
33+
@include media-breakpoint-down(sm) {
34+
.card-img-top {
35+
margin-bottom: .25rem;
36+
}
37+
}
38+
39+
@include media-breakpoint-up(md) {
40+
.card-img-top {
41+
border-radius: 0 !important;
42+
}
43+
44+
.hb-blog-post-card-img {
45+
height: 100%;
46+
width: 180px;
47+
}
48+
}
49+
50+
@include media-breakpoint-up(lg) {
51+
.hb-blog-post-card-img {
52+
width: 240px;
53+
}
54+
}
55+
}

hugo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ post_date_format = ':date_long'
2929
post_thumbnail = true
3030
post_thumbnail_placeholder = ""
3131
post_thumbnail_default = "images/thumbnail.png"
32+
post_thumbnail_position = "top"
3233
list_cols_md = 2
3334
list_cols_lg = 3 # won't work when sidebar was enabled.
3435

layouts/partials/hb/modules/blog/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
</div>
1818
{{- if $hasPinned }}
1919
<div class="col-12 col-lg-6">
20-
{{ partial "hb/modules/blog/posts" (dict "Pages" $pinnedPages "Cols" "row-cols-1" "ReadMore" false) }}
20+
{{- $ctx := dict "Page" (index $pinnedPages 0) "ReadMore" false }}
21+
{{ partial "hb/modules/blog/post/card" $ctx }}
2122
</div>
2223
{{- end }}
2324
</div>

layouts/partials/hb/modules/blog/post/card.html

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,80 @@
1111
{{- $meta := default true .Meta }}
1212
{{- $pageMeta := default dict $page.Params.meta }}
1313
{{- $modularize := default true .Modularize }}
14+
{{- $thumbnail := default true site.Params.hb.blog.post_thumbnail }}
15+
{{- $thumbnailPos := "top" }}
16+
{{- if eq .Caller "list" }}
17+
{{- $thumbnailPos = site.Params.hb.blog.post_thumbnail_position }}
18+
{{- end }}
1419
<div
1520
class="hb-blog-post-card card border-0 overflow-hidden h-100{{ cond $modularize ` hb-module` ` bg-transparent` }} mb-0">
16-
{{- if and $meta (ne $pageMeta false) }}
17-
<div class="hb-blog-post-meta d-flex align-items-center">
18-
{{- if default true $pageMeta.authors }}
19-
{{ partialCached "hb/modules/blog/post/meta/authors" $page $page }}
20-
{{- end }}
21-
{{- if default true $pageMeta.date }}
22-
{{ partialCached "hb/modules/blog/post/meta/date" $page $page }}
23-
{{- end }}
24-
{{- if and $readingTime (default true $pageMeta.reading_time) }}
25-
{{ partialCached "hb/modules/blog/post/meta/reading-time" $page $page }}
26-
{{- end }}
27-
{{ partialCached "hb/modules/blog/post/meta/first-section" $page $page }}
28-
</div>
29-
{{- end }}
30-
{{- if default true site.Params.hb.blog.post_thumbnail }}
31-
{{ partial "hb/modules/blog/post/card-img" $page }}
21+
{{- if and $thumbnail (ne $thumbnailPos "top") }}
22+
{{ printf `<div class="d-flex flex-column flex-md-row">` | safeHTML }}
23+
<div class="hb-blog-post-card-wrapper me-md-2 mt-2 mt-md-0">
24+
{{ partial "hb/modules/blog/post/card-img" $page }}
25+
</div>
3226
{{- end }}
33-
<div class="card-body px-0 py-2 d-flex flex-column">
34-
<div class="hb-blog-post-title card-title h5 py-1">
35-
<a
36-
class="hb-blog-post-title-link d-block"
37-
title="{{ $page.Title }}"
38-
{{ if $external }}target="_blank" rel="external"{{ end }}
39-
href="{{ $url }}">
40-
{{- if $page.Params.pinned }}
41-
{{- partialCached "hb/modules/blog/helpers/pinned-icon" . -}}
27+
<div class="hb-blog-post-card-body overflow-hidden">
28+
{{- if and $meta (ne $pageMeta false) }}
29+
<div class="hb-blog-post-meta d-flex align-items-center">
30+
{{- if default true $pageMeta.authors }}
31+
{{ partialCached "hb/modules/blog/post/meta/authors" $page $page }}
4232
{{- end }}
43-
{{- $page.Title -}}
44-
{{- if $external }}
45-
{{- partial "icons/icon" (dict "vendor" "bootstrap" "name" "box-arrow-up-right" "className" "ms-1") }}
33+
{{- if default true $pageMeta.date }}
34+
{{ partialCached "hb/modules/blog/post/meta/date" $page $page }}
4635
{{- end }}
47-
</a>
48-
</div>
49-
{{- if and $meta (ne $pageMeta false) (default true $pageMeta.taxonomies) }}
50-
<div class="hb-blog-post-meta d-block text-nowrap text-truncate mb-2">
51-
{{ partialCached "hb/modules/blog/post/meta/taxonomies" $page $page }}
36+
{{- if and $readingTime (default true $pageMeta.reading_time) }}
37+
{{ partialCached "hb/modules/blog/post/meta/reading-time" $page $page }}
38+
{{- end }}
39+
{{ partialCached "hb/modules/blog/post/meta/first-section" $page $page }}
5240
</div>
5341
{{- end }}
54-
{{- if $showSummary }}
55-
{{- $summary := $page.Summary }}
56-
{{- $truncated := $page.Truncated }}
57-
{{- with $page.Description }}
58-
{{- $summary = . }}
59-
{{- $truncated := true }}
60-
{{- end }}
61-
<div class="hb-blog-post-summary card-text text-secondary mb-auto">
62-
{{- $summary -}}
42+
{{- if and $thumbnail (eq $thumbnailPos "top") }}
43+
{{ partial "hb/modules/blog/post/card-img" $page }}
44+
{{- end }}
45+
<div class="card-body px-0 py-2 d-flex flex-column">
46+
<div class="hb-blog-post-title card-title h5 py-1">
47+
<a
48+
class="hb-blog-post-title-link d-block"
49+
title="{{ $page.Title }}"
50+
{{ if $external }}target="_blank" rel="external"{{ end }}
51+
href="{{ $url }}">
52+
{{- if $page.Params.pinned }}
53+
{{- partialCached "hb/modules/blog/helpers/pinned-icon" . -}}
54+
{{- end }}
55+
{{- $page.Title -}}
56+
{{- if $external }}
57+
{{- partial "icons/icon" (dict "vendor" "bootstrap" "name" "box-arrow-up-right" "className" "ms-1") }}
58+
{{- end }}
59+
</a>
6360
</div>
64-
{{- if and $readMore $truncated }}
65-
<div class="mt-2">
66-
<a
67-
class="text-secondary" href="{{ $url }}"{{ if $external }}target="_blank" rel="external"{{ end }}>
68-
{{- i18n "read_more_about" $page.Title -}}
69-
</a>
61+
{{- if and $meta (ne $pageMeta false) (default true $pageMeta.taxonomies) }}
62+
<div class="hb-blog-post-meta d-block text-nowrap text-truncate mb-2">
63+
{{ partialCached "hb/modules/blog/post/meta/taxonomies" $page $page }}
7064
</div>
7165
{{- end }}
72-
{{- end }}
66+
{{- if $showSummary }}
67+
{{- $summary := $page.Summary }}
68+
{{- $truncated := $page.Truncated }}
69+
{{- with $page.Description }}
70+
{{- $summary = . }}
71+
{{- $truncated := true }}
72+
{{- end }}
73+
<div class="hb-blog-post-summary card-text text-secondary mb-auto">
74+
{{- $summary -}}
75+
</div>
76+
{{- if and $readMore $truncated }}
77+
<div class="mt-2">
78+
<a
79+
class="text-secondary" href="{{ $url }}"{{ if $external }}target="_blank" rel="external"{{ end }}>
80+
{{- i18n "read_more_about" $page.Title -}}
81+
</a>
82+
</div>
83+
{{- end }}
84+
{{- end }}
85+
</div>
7386
</div>
87+
{{- if and $thumbnail (ne $thumbnailPos "top") }}
88+
{{ printf `</div>` | safeHTML }}
89+
{{- end }}
7490
</div>

layouts/partials/hb/modules/blog/posts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="hb-blog-posts row {{ $cols }} g-3 mb-3">
55
{{ range .Pages }}
66
<div class="col">
7-
{{- $ctx := dict "Page" . "ReadMore" $readMore "Modularize" $modularize }}
7+
{{- $ctx := dict "Page" . "ReadMore" $readMore "Modularize" $modularize "Caller" "list" }}
88
{{ partial "hb/modules/blog/post/card" $ctx }}
99
</div>
1010
{{ end }}

0 commit comments

Comments
 (0)