feat: add support for compactSummary option in article shortcode

This commit is contained in:
ZhenShuo Leo
2025-07-01 00:42:56 +08:00
parent ad1ba9905d
commit 965c241f8c
3 changed files with 16 additions and 2 deletions
+6
View File
@@ -1028,6 +1028,12 @@ body.zen-mode-enable {
height: 8px; height: 8px;
} }
} }
.line-clamp-3 {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
.\!block { .\!block {
display: block !important; display: block !important;
} }
@@ -1,5 +1,6 @@
{{ $target := .target }} {{ $target := .target }}
{{ $shortcodeShowSummary := .showSummary }} {{ $shortcodeShowSummary := .showSummary }}
{{ $shortcodeCompactSummary := .compactSummary }}
{{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }} {{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }}
{{ $disableImageOptimization := site.Params.disableImageOptimization | default false }} {{ $disableImageOptimization := site.Params.disableImageOptimization | default false }}
@@ -103,8 +104,14 @@
{{ $showSummary = $target.Params.showSummary | default (site.Params.list.showSummary | default false) }} {{ $showSummary = $target.Params.showSummary | default (site.Params.list.showSummary | default false) }}
{{ end }} {{ end }}
{{ if $showSummary }} {{ if $showSummary }}
{{ $compactSummary := false }}
{{ if ne $shortcodeCompactSummary nil }}
{{ $compactSummary = $shortcodeCompactSummary }}
{{ else }}
{{ $compactSummary = $target.Params.compactSummary | default (site.Params.list.compactSummary | default false) }}
{{ end }}
<div class="overflow-hidden pt-1"> <div class="overflow-hidden pt-1">
<div class="prose dark:prose-invert max-w-fit"> <div class="{{ if $compactSummary }}line-clamp-3{{ end }} max-w-fit prose dark:prose-invert">
{{ $target.Summary | plainify }} {{ $target.Summary | plainify }}
</div> </div>
</div> </div>
+2 -1
View File
@@ -1,12 +1,13 @@
{{ $link := .Get "link" }} {{ $link := .Get "link" }}
{{ $showSummary := .Get "showSummary" }} {{ $showSummary := .Get "showSummary" }}
{{ $compactSummary := .Get "compactSummary" | default false }}
{{ $target := .Page }} {{ $target := .Page }}
{{ if ne $link .Page.RelPermalink }} {{ if ne $link .Page.RelPermalink }}
{{ $target = index (first 1 (where .Site.AllPages "RelPermalink" $link)) 0 }} {{ $target = index (first 1 (where .Site.AllPages "RelPermalink" $link)) 0 }}
{{ end }} {{ end }}
{{ if $target }} {{ if $target }}
<section class="space-y-10 w-full"> <section class="space-y-10 w-full">
{{ $context := dict "target" $target "showSummary" $showSummary }} {{ $context := dict "target" $target "showSummary" $showSummary "compactSummary" $compactSummary }}
{{ partial "article-link/_shortcode.html" $context }} {{ partial "article-link/_shortcode.html" $context }}
</section> </section>
{{ end }} {{ end }}