From 58246136dea0768b5ac57eeb671a21d84e7d4b72 Mon Sep 17 00:00:00 2001 From: razonyang Date: Mon, 3 Jul 2023 15:24:58 +0800 Subject: [PATCH] feat: add the article-cards shortcode --- config.toml | 3 + go.mod | 5 +- go.sum | 6 +- i18n/en.toml | 3 + i18n/zh-hans.toml | 3 + i18n/zh-hant.toml | 3 + layouts/partials/bootstrap/article-cards.html | 64 +++++++++++++++++++ .../shortcodes/bootstrap/article-cards.html | 1 + layouts/shortcodes/bs/article-cards.html | 1 + 9 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 layouts/partials/bootstrap/article-cards.html create mode 100644 layouts/shortcodes/bootstrap/article-cards.html create mode 100644 layouts/shortcodes/bs/article-cards.html diff --git a/config.toml b/config.toml index b69edeb..cdf5f4a 100644 --- a/config.toml +++ b/config.toml @@ -3,3 +3,6 @@ min = "0.110.0" [[module.imports]] path = "github.com/hugomods/icons/vendors/bootstrap" + +[[module.imports]] +path = "github.com/hugomods/images" diff --git a/go.mod b/go.mod index 45689df..894fae6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/hugomods/bootstrap go 1.19 -require github.com/hugomods/icons/vendors/bootstrap v0.5.0 // indirect +require ( + github.com/hugomods/icons/vendors/bootstrap v0.5.0 // indirect + github.com/hugomods/images v0.7.0 // indirect +) diff --git a/go.sum b/go.sum index 3940140..ab3e4d5 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ github.com/hugomods/icons v0.6.0 h1:G6RU93okhPPRDh/jqcew9gwkcYpSpg0rCBv4S6yUAFw= -github.com/hugomods/icons/vendors/bootstrap v0.4.0 h1:+2r0aWG/qdsdLBtQ+b5VN7z3Kh/M0/TduF9ZxW0d9Kg= -github.com/hugomods/icons/vendors/bootstrap v0.4.0/go.mod h1:my/xxEyTvWAym67NVfhWRvdQKrHcscU43neIBXnlbfM= -github.com/hugomods/icons/vendors/bootstrap v0.4.1/go.mod h1:3fXUsXdGZa+f31OEKUMDGsrCq1XZwhLvUys8XT63AZM= +github.com/hugomods/icons/vendors/bootstrap v0.5.0 h1:CHEGk677heq2kJZa7XsGHRc3Hwizl9NFkmNw146OVm0= github.com/hugomods/icons/vendors/bootstrap v0.5.0/go.mod h1:kfC17VWV+tNi6PGF4AY7CJBBa1/HEgWxCYq2kNOdcdI= +github.com/hugomods/images v0.7.0 h1:NEGgCSrh1YuHGmTAL9wDAKLdXL4WU6Nw4BfkampJxyM= +github.com/hugomods/images v0.7.0/go.mod h1:U6Gwj16LKvk66rOMyGFrnF6f0aV8lT89lqOsckOAjYY= diff --git a/i18n/en.toml b/i18n/en.toml index 27f2802..eb0a2c9 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -1,2 +1,5 @@ [learn_more] other = "Learn more" + +[read_more] +other = "Read more" diff --git a/i18n/zh-hans.toml b/i18n/zh-hans.toml index a5cef22..ca64451 100644 --- a/i18n/zh-hans.toml +++ b/i18n/zh-hans.toml @@ -1,2 +1,5 @@ [learn_more] other = "了解详情" + +[read_more] +other = "阅读更多" diff --git a/i18n/zh-hant.toml b/i18n/zh-hant.toml index 5edf111..500b15e 100644 --- a/i18n/zh-hant.toml +++ b/i18n/zh-hant.toml @@ -1,2 +1,5 @@ [learn_more] other = "瞭解詳情" + +[read_more] +other = "閱讀更多" diff --git a/layouts/partials/bootstrap/article-cards.html b/layouts/partials/bootstrap/article-cards.html new file mode 100644 index 0000000..20b30c8 --- /dev/null +++ b/layouts/partials/bootstrap/article-cards.html @@ -0,0 +1,64 @@ +{{- $summaryLen := 120 }} +{{- $limit := 12 }} +{{- $sections := slice }} +{{- if .IsNamedParams }} + {{- with .Get "limit" }}{{ $limit = . }}{{ end }} + {{- with .Get "summaryLen" }}{{ $summaryLen = . }}{{ end }} + {{- with .Get "sections" }}{{ $sections = split . "," }}{{ end }} +{{- end }} +{{- $pages := site.RegularPages }} +{{- with $sections }} + {{- $pages = where $pages "Section" "in" . }} +{{- end }} +
+ {{- range first $limit $pages }} +
+
+ {{- with .FirstSection }} + + {{- .Title -}} + + {{- end }} + + {{- .Date | time.Format ":date_medium" -}} + + {{- $img := partial "images/functions/page-thumbnail" (dict + "Page" . + "ClassName" "card-img-top object-fit-cover bg-secondary-subtle" + "LazyLoading" false + "Style" (slice "height: 160px;")) + }} + {{- with $img }} + {{ . }} + {{- else }} +
+ NO IMAGE +
+ {{- end }} + +
+
+ {{- end }} +
diff --git a/layouts/shortcodes/bootstrap/article-cards.html b/layouts/shortcodes/bootstrap/article-cards.html new file mode 100644 index 0000000..55e7357 --- /dev/null +++ b/layouts/shortcodes/bootstrap/article-cards.html @@ -0,0 +1 @@ +{{ partial "bootstrap/article-cards" . }} diff --git a/layouts/shortcodes/bs/article-cards.html b/layouts/shortcodes/bs/article-cards.html new file mode 100644 index 0000000..55e7357 --- /dev/null +++ b/layouts/shortcodes/bs/article-cards.html @@ -0,0 +1 @@ +{{ partial "bootstrap/article-cards" . }}