From b4a7741b39e12a8ad6d2bb90255ea0aeb130ae1e Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Tue, 1 Jul 2025 01:24:34 +0800 Subject: [PATCH] feat: add support for showSummary in article shortcode --- assets/css/compiled/main.css | 12 ++ layouts/partials/article-link/_shortcode.html | 113 ++++++++++++++++++ layouts/shortcodes/article.html | 4 +- 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/article-link/_shortcode.html diff --git a/assets/css/compiled/main.css b/assets/css/compiled/main.css index 7ca3ba0b..8f462959 100644 --- a/assets/css/compiled/main.css +++ b/assets/css/compiled/main.css @@ -1689,6 +1689,9 @@ body.zen-mode-enable { .p-1\.5 { padding: calc(var(--spacing) * 1.5); } + .p-2\.5 { + padding: calc(var(--spacing) * 2.5); + } .p-4 { padding: calc(var(--spacing) * 4); } @@ -1758,6 +1761,9 @@ body.zen-mode-enable { .py-\[1px\] { padding-block: 1px; } + .pt-1 { + padding-top: calc(var(--spacing) * 1); + } .pt-2 { padding-top: calc(var(--spacing) * 2); } @@ -1785,6 +1791,9 @@ body.zen-mode-enable { .pr-\[24px\] { padding-right: 24px; } + .pb-0 { + padding-bottom: calc(var(--spacing) * 0); + } .pb-2 { padding-bottom: calc(var(--spacing) * 2); } @@ -1809,6 +1818,9 @@ body.zen-mode-enable { .pl-2 { padding-left: calc(var(--spacing) * 2); } + .pl-4 { + padding-left: calc(var(--spacing) * 4); + } .pl-\[24px\] { padding-left: 24px; } diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html new file mode 100644 index 00000000..79756146 --- /dev/null +++ b/layouts/partials/article-link/_shortcode.html @@ -0,0 +1,113 @@ +{{ $target := .target }} +{{ $shortcodeShowSummary := .showSummary }} +{{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }} +{{ $disableImageOptimization := site.Params.disableImageOptimization | default false }} + +{{ $articleClasses := "flex flex-wrap md:flex-nowrap article" }} +{{ if site.Params.list.showCards }} + {{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }} +{{ else }} + {{ $articleClasses = delimit (slice $articleClasses "") " " }} +{{ end }} + +{{ $articleImageClasses := "w-full md:w-auto h-full thumbnail nozoom" }} +{{ if site.Params.list.showCards }} + {{ $articleImageClasses = delimit (slice $articleImageClasses "") " " }} +{{ else }} + {{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }} +{{ end }} + +{{ $articleInnerClasses := "" }} +{{ if site.Params.list.showCards }} + {{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-2.5 pl-4 pb-0") " " }} +{{ else }} + {{ $articleInnerClasses = delimit (slice $articleInnerClasses "mt-3 md:mt-0") " " }} +{{ end }} + +{{ if $constrainItemsWidth }} + {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} +{{ end }} + + + + {{- with $target.Params.images -}} + {{- range first 6 . }} + + {{ end -}} + {{- else -}} + {{- $images := $target.Resources.ByType "image" -}} + {{- $featured := $images.GetMatch "*feature*" -}} + {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} + {{ if and $target.Params.featureimage (not $featured) }} + {{- $url:= $target.Params.featureimage -}} + {{ $featured = resources.GetRemote $url }} + {{ end }} + {{- if not $featured }} + {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end -}} + {{ if $target.Params.hideFeatureImage }}{{ $featured = false }}{{ end }} + {{- with $featured -}} + {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} + {{ with . }} +
+ {{ end }} + {{ else }} + {{ with .Resize "600x" }} +
+ {{ end }} + {{ end }} + {{- else -}} + {{- with site.Params.images }} + + {{ end -}} + {{- end -}} + {{- end -}} + + +
+
+ {{ with $target.Params.externalUrl }} +
+
+ {{ $target.Title | emojify }} + + + + +
+
+ {{ else }} +
+ {{ $target.Title | emojify }} +
+ {{ end }} + {{ if and $target.Draft site.Params.article.showDraftLabel }} +
+ {{ partial "badge.html" (i18n "article.draft" | emojify) }} +
+ {{ end }} + {{ if templates.Exists "partials/extend-article-link.html" }} + {{ partial "extend-article-link.html" $target }} + {{ end }} +
+
+ {{ partial "article-meta/basic.html" $target }} +
+ {{ $showSummary := false }} + {{ if ne $shortcodeShowSummary nil }} + {{ $showSummary = $shortcodeShowSummary }} + {{ else }} + {{ $showSummary = $target.Params.showSummary | default (site.Params.list.showSummary | default false) }} + {{ end }} + {{ if $showSummary }} +
+
+ {{ $target.Summary | plainify }} +
+
+ {{ end }} +
+
diff --git a/layouts/shortcodes/article.html b/layouts/shortcodes/article.html index b85a3ca2..f71181b6 100644 --- a/layouts/shortcodes/article.html +++ b/layouts/shortcodes/article.html @@ -1,10 +1,12 @@ {{ $link := .Get "link" }} +{{ $showSummary := .Get "showSummary" }} {{ $target := .Page }} {{ if ne $link .Page.RelPermalink }} {{ $target = index (first 1 (where .Site.AllPages "RelPermalink" $link)) 0 }} {{ end }} {{ if $target }}
- {{ partial "article-link/simple.html" $target }} + {{ $context := dict "target" $target "showSummary" $showSummary }} + {{ partial "article-link/_shortcode.html" $context }}
{{ end }}