Skip to content

Commit

Permalink
feat: add the hb.blog.post_thumbnail_height parameter, which repres…
Browse files Browse the repository at this point in the history
…ents the height of thumbnail, default to `160px` (#809)

feat: add the `hb.blog.post_thumbnail_resize_height` parameter for changing the height for resizing thumbnails, default to `360`.
  • Loading branch information
razonyang committed May 1, 2024
1 parent dfd2ff4 commit 6f49989
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions assets/hb/modules/blog/scss/post/_card.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.hb-blog-post-card-img {
height: 160px;
height: $hb-blog-post-thumbnail-height;
object-fit: cover;
width: 100%;
transition: 0.3s;
Expand All @@ -11,7 +11,7 @@

.hb-blog-post-card-img-none {
background: rgba(var(--#{$prefix}body-color-rgb), 0.1);
height: 160px;
height: $hb-blog-post-thumbnail-height;
filter: blur(1px);
font-size: 1.5rem;
text-transform: uppercase;
Expand Down
3 changes: 3 additions & 0 deletions assets/hb/modules/blog/scss/variables.tmpl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ $hb-blog-home-pinned-posts-pos: '{{ default "" site.Params.hb.blog.home.pinned_p

// ToC
$hb-blog-toc-position: {{ default "end" site.Params.hb.blog.toc.position }};

// Thumbnail
$hb-blog-post-thumbnail-height: {{ default "160px" site.Params.hb.blog.post_thumbnail_height }};
2 changes: 2 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ full_width = false
paginate = 12
post_date_format = ':date_long'
post_thumbnail = true
post_thumbnail_height = "160px"
post_thumbnail_placeholder = ""
post_thumbnail_default = "images/thumbnail.png"
post_thumbnail_position = "top"
post_thumbnail_resize_height = 360
list_cols_md = 2
list_cols_lg = 3 # won't work when sidebar was enabled.

Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/hb/modules/blog/post/card-img.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
{{- $img = index . 0 }}
{{- else }}
{{- $res := partialCached "hb/functions/page-thumbnail" . . }}
{{- $thumbnailHeight := default 360 site.Params.hb.blog.post_thumbnail_resize_height }}
{{- if $res }}
{{- $img = replace $res.Permalink $page.Permalink "" | printf "%s?height=360" }}
{{- $img = printf "%s?height=%d" (replace $res.Permalink $page.Permalink "") $thumbnailHeight }}
{{- else }}
{{/* Get the default thumbnail if set. */}}
{{- $default := site.Params.hb.blog.post_thumbnail_default }}
{{- with resources.Get $default }}
{{- $img = strings.TrimPrefix "/" $default | printf "/%s?height=360" }}
{{- $img = printf "/%s?height=%d" (strings.TrimPrefix "/" $default) $thumbnailHeight }}
{{- end }}
{{- end }}
{{- end -}}
Expand Down

0 comments on commit 6f49989

Please sign in to comment.