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

View File

@@ -1028,6 +1028,12 @@ body.zen-mode-enable {
height: 8px;
}
}
.line-clamp-3 {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
.\!block {
display: block !important;
}

View File

@@ -1,5 +1,6 @@
{{ $target := .target }}
{{ $shortcodeShowSummary := .showSummary }}
{{ $shortcodeCompactSummary := .compactSummary }}
{{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }}
{{ $disableImageOptimization := site.Params.disableImageOptimization | default false }}
@@ -103,8 +104,14 @@
{{ $showSummary = $target.Params.showSummary | default (site.Params.list.showSummary | default false) }}
{{ end }}
{{ 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="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 }}
</div>
</div>

View File

@@ -1,12 +1,13 @@
{{ $link := .Get "link" }}
{{ $showSummary := .Get "showSummary" }}
{{ $compactSummary := .Get "compactSummary" | default false }}
{{ $target := .Page }}
{{ if ne $link .Page.RelPermalink }}
{{ $target = index (first 1 (where .Site.AllPages "RelPermalink" $link)) 0 }}
{{ end }}
{{ if $target }}
<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 }}
</section>
{{ end }}