refactor(article-link): separate Go templates from HTML rendering

Add descriptions for the purpose of each template.
It takes time to figure out their use every time.
This commit is contained in:
ZhenShuo Leo
2025-08-31 17:16:10 +08:00
parent c8ee5fc657
commit 0f7f27b916
4 changed files with 103 additions and 71 deletions
+24 -18
View File
@@ -1,3 +1,6 @@
{{/* Used by
1. article shortcode
*/}}
{{ $target := .target }}
{{ $shortcodeShowSummary := .showSummary }}
{{ $shortcodeCompactSummary := .compactSummary }}
@@ -29,30 +32,33 @@
{{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }}
{{ end }}
{{ $images := $target.Resources.ByType "image" }}
{{ $featured := $images.GetMatch "*feature*" }}
{{ $featuredURL := "" }}
{{ 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 }}
{{ $featuredURL = .RelPermalink }}
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
{{ $featuredURL = (.Resize "600x").RelPermalink }}
{{ end }}
{{ end }}
<div class="{{ $articleClasses }}">
<a
{{ partial "article-link/_external-link.html" $target | safeHTMLAttr }}
class="absolute inset-0"
aria-label="{{ $.Title }}"></a>
{{ $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 }}
{{ $featuredURL := .RelPermalink }}
{{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
{{ $featuredURL = (.Resize "600x").RelPermalink }}
{{ end }}
<div class="{{ $articleImageClasses }}" style="background-image:url({{ $featuredURL }});"></div>
{{ with $featuredURL }}
<div class="{{ $articleImageClasses }}" style="background-image:url({{ . }});"></div>
{{ end }}
<div class="{{ $articleInnerClasses }}">
<div class="items-center text-start text-xl font-semibold">