diff options
| author | Arne Rief <riearn@proton.me> | 2025-08-16 22:42:03 +0200 |
|---|---|---|
| committer | Arne Rief <riearn@proton.me> | 2025-08-16 22:42:03 +0200 |
| commit | f0506acd6f70da636b8fdb23439c85bbf2392b40 (patch) | |
| tree | d9c4082aafa3e20a37174beecadcab54286f9cd9 /layouts/partials/list/recent-posts.html | |
| parent | 1bf4d8aca6f81f2dddd0262e74b278cd9985b53d (diff) | |
HTML templates done
Diffstat (limited to 'layouts/partials/list/recent-posts.html')
| -rw-r--r-- | layouts/partials/list/recent-posts.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/layouts/partials/list/recent-posts.html b/layouts/partials/list/recent-posts.html new file mode 100644 index 0000000..c1075e2 --- /dev/null +++ b/layouts/partials/list/recent-posts.html @@ -0,0 +1,50 @@ +{{- /* +List of Recent Posts. Accepts a dict with the following optional parameters: + +@context {int} count: Number of posts to display (default: 10). +@context {string} title: Section title (default: "Recent Articles"). +@context {bool} show_view_all: Whether to show "View All Posts" link (default: true). + +@example: {{ partial "list/recent-posts.html" (dict "count" 20 "title" "Latest updates" "show_view_all" true) }} +*/ -}} + +{{- $count := .count | default 10 -}} +{{- $title := .title | default (lang.Translate "posts.recent" | default "Recent Articles") -}} +{{- $showViewAll := .show_view_all | default true -}} + +<section class="recent-posts" aria-labelledby="recent-posts-heading"> + <header class="recent-posts__header"> + <h2 id="recent-posts-heading" class="recent-posts__title"> + {{ $title }} + </h2> + </header> + + {{- /* Get published 10 most recent posts */ -}} + {{- $recentPosts := where site.RegularPages "Date" "!=" nil }} + {{- $recentPosts = where $recentPosts ".Date" "le" now }} + {{- $recentPosts = first $count $recentPosts }} + + {{- if $recentPosts }} + <div class="recent-posts__content"> + <ul class="recent-posts__list" role="list"> + {{- range $recentPosts }} + <li class="recent-posts__list-item"> + {{- partial "list/post-card.html" . }} + </li> + {{- end }} + </ul> + + {{- if $showViewAll }} + <a href="{{ with site.GetPage "/posts" }}{{ .RelPermalink }}{{ else }}/posts/{{ end }}" class="recent_posts__view-all-link"> + {{ lang.Translate "posts.view_all" | default "View all posts" }} + </a> + {{- end }} + </div> + {{ else }} + <div class="recent-posts__empty"> + <p class="recent_posts__empty-message"> + {{ lang.Translate "list.empty" | default "No posts in this section." }} + </p> + </div> + {{- end }} +</section> |
