diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-17 16:02:40 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-17 16:02:40 +0200 |
| commit | 0280cbf618db38255e878fc4b1bd474223782696 (patch) | |
| tree | 517cb92edc3e81dad23b2c4e0c4f28ee2f96fa55 /themes | |
| parent | e2737855a3d3544e7a44ba8384be1e206e96c40f (diff) | |
| download | danixxyz-0280cbf618db38255e878fc4b1bd474223782696.tar.gz danixxyz-0280cbf618db38255e878fc4b1bd474223782696.zip | |
feat: implement Related Articles sidebar widget
Replaces stub implementation with full related content functionality:
- Uses Hugo's .Site.RegularPages.Related API for smart tagging
- Caps at 5 related articles to keep sidebar compact
- Shows 2-line compact card per entry (title + date, excerpt snippet)
- Left border colored by article type (var(--type-<type>))
- Includes empty state message when no related articles found
- Multilingual support via existing i18n keys
- Theme-aware styling via CSS custom properties
The widget shows:
- Line 1: Title (linked) + · Jan 2006 date inline
- Line 2: First ~10 words of excerpt, small font, muted
Previously was a stub with empty placeholder comment.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'themes')
| -rw-r--r-- | themes/danix-xyz-hacker/layouts/partials/sidebar.html | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/themes/danix-xyz-hacker/layouts/partials/sidebar.html b/themes/danix-xyz-hacker/layouts/partials/sidebar.html index f552df9..574eb85 100644 --- a/themes/danix-xyz-hacker/layouts/partials/sidebar.html +++ b/themes/danix-xyz-hacker/layouts/partials/sidebar.html @@ -9,14 +9,35 @@ <!-- Related posts widget (optional) --> {{ if .Site.Params.relatedPosts }} - {{ $related := .GetTerms "tags" }} - {{ if $related }} - <div class="p-4 border border-border/30 rounded"> + {{ $related := first 5 (.Site.RegularPages.Related .) }} + <div class="p-4 border border-border/30 rounded mb-6"> <h3 class="text-lg font-semibold text-accent mb-3">{{ i18n "relatedPosts" }}</h3> - <div class="space-y-2"> - <!-- Related articles can be implemented here --> - </div> + {{ if $related }} + <ul class="space-y-3"> + {{ range $related }} + {{ $articleType := .Params.type | default "life" }} + {{ $excerpt := .Description | default .Summary }} + <li + class="pl-3 border-l-2" + style="border-color: var(--type-{{ $articleType }});" + > + <a href="{{ .RelPermalink }}" class="text-sm hover:text-accent transition-colors leading-snug block"> + {{ .Title }} + <time class="text-text-dim/60 ml-1" datetime="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}"> + · {{ .PublishDate.Format "Jan 2006" }} + </time> + </a> + {{ if $excerpt }} + <p class="text-xs text-text-dim/70 leading-snug mt-0.5 line-clamp-1"> + {{ $excerpt | plainify | truncate 60 }} + </p> + {{ end }} + </li> + {{ end }} + </ul> + {{ else }} + <p class="text-sm text-text-dim">{{ i18n "noRelated" }}</p> + {{ end }} </div> {{ end }} - {{ end }} </aside> |
