blob: c1075e204178f8044926ab0efd8a8d77caebbd8e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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>
|