From f5be4a7a16687708c910fbfce79c6b8de315383c Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Sat, 16 Dec 2023 13:57:59 +0800 Subject: [PATCH] feat: add the site.Params.hb.blog.list_cols_md and site.Params.hb.blog.list_cols_lg parameter to specify cols for md and lg breakpoints respectively (#554) --- hugo.toml | 2 ++ layouts/partials/hb/modules/blog/functions/list-cols.html | 5 +++++ layouts/partials/hb/modules/blog/index.html | 5 +---- layouts/partials/hb/modules/blog/list.html | 5 +---- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 layouts/partials/hb/modules/blog/functions/list-cols.html diff --git a/hugo.toml b/hugo.toml index 7f2fc693..20785f27 100644 --- a/hugo.toml +++ b/hugo.toml @@ -32,6 +32,8 @@ post_date_format = ':date_long' post_thumbnail = true post_thumbnail_placeholder = "" post_thumbnail_default = "images/thumbnail.png" +list_cols_md = 2 +list_cols_lg = 3 # won't work when sidebar was enabled. [params.hb.blog.archives] paginate = 30 diff --git a/layouts/partials/hb/modules/blog/functions/list-cols.html b/layouts/partials/hb/modules/blog/functions/list-cols.html new file mode 100644 index 00000000..32f9c9a5 --- /dev/null +++ b/layouts/partials/hb/modules/blog/functions/list-cols.html @@ -0,0 +1,5 @@ +{{- $cols := printf "row-cols-1 row-cols-md-%d" (default 2 site.Params.hb.blog.list_cols_md) }} +{{- if not (partialCached "hb/modules/blog/functions/has-sidebar" .) }} + {{- $cols = printf "%s row-cols-lg-%d" $cols (default 3 site.Params.hb.blog.list_cols_lg) }} +{{- end }} +{{- return $cols }} diff --git a/layouts/partials/hb/modules/blog/index.html b/layouts/partials/hb/modules/blog/index.html index 131bc455..9ccdf9fa 100644 --- a/layouts/partials/hb/modules/blog/index.html +++ b/layouts/partials/hb/modules/blog/index.html @@ -28,10 +28,7 @@ {{ partialCached "hb/modules/blog/home/taxonomies" . }} {{- end }} {{- with .Paginator }} - {{- $cols := "row-cols-1 row-cols-md-2" }} - {{- if not (partialCached "hb/modules/blog/functions/has-sidebar" .) }} - {{- $cols = printf "%s row-cols-lg-3" $cols }} - {{- end }} + {{- $cols := partialCached "hb/modules/blog/functions/list-cols" . }} {{ partial "hb/modules/blog/posts" (dict "Pages" .Pages "Cols" $cols) }} {{ partial "hb/modules/pagination/index" . }} {{- end }} diff --git a/layouts/partials/hb/modules/blog/list.html b/layouts/partials/hb/modules/blog/list.html index 630e676e..003f2aae 100644 --- a/layouts/partials/hb/modules/blog/list.html +++ b/layouts/partials/hb/modules/blog/list.html @@ -1,10 +1,7 @@
{{ partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-main-begin" "Page" .) }} - {{- $cols := "row-cols-1 row-cols-md-2" }} - {{- if not (partialCached "hb/modules/blog/functions/has-sidebar" .) }} - {{- $cols = printf "%s row-cols-lg-3" $cols }} - {{- end }} + {{- $cols := partialCached "hb/modules/blog/functions/list-cols" . }} {{ partial "hb/modules/blog/posts" (dict "Pages" .Paginator.Pages "Cols" $cols) }} {{ partial "hb/modules/pagination/index" .Paginator }} {{ partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-main-end" "Page" .) }}