diff options
| author | yingyu5658 <i@yingyu5658.me> | 2025-12-13 08:33:08 +0800 |
|---|---|---|
| committer | yingyu5658 <i@yingyu5658.me> | 2025-12-13 08:33:08 +0800 |
| commit | 1e5f8eb33bc41cb59faf059e83701152785cabea (patch) | |
| tree | 45867273ac2178285be840764f7962d2b55556c6 /layouts/shortcodes/recent-posts.html | |
| download | blog-1e5f8eb33bc41cb59faf059e83701152785cabea.tar.gz blog-1e5f8eb33bc41cb59faf059e83701152785cabea.zip | |
Initial commit
Diffstat (limited to 'layouts/shortcodes/recent-posts.html')
| -rw-r--r-- | layouts/shortcodes/recent-posts.html | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/layouts/shortcodes/recent-posts.html b/layouts/shortcodes/recent-posts.html new file mode 100644 index 0000000..c6c1a3e --- /dev/null +++ b/layouts/shortcodes/recent-posts.html @@ -0,0 +1,55 @@ +{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} {{ +$recent := first 5 $pages.ByDate.Reverse }} +<style> + .recent-list { + margin: 0; + } + + .recent-item { + position: relative; + margin-bottom: 8px; + display: flex; + align-items: flex-start; + } + + .item-link { + display: inline-block; + text-decoration: none; + margin-left: 10px; + flex: 1; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + .post-date { + font-size: 0.9em; + color: #666; + display: inline-block; + min-width: 80px; + flex-shrink: 0; + } + + .recent-empty { + text-align: center; + font-style: italic; + } +</style> +<div class="recent-posts"> + {{ if $recent }} + <ul class="recent-list"> + {{ range $index, $page := $recent }} + <li class="recent-item"> + <span class="post-date"> + <time datetime='{{ .Date.Format "2006-01-02" }}'> + {{ .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }} + </time> + </span> + <a href="{{ .RelPermalink }}" class="item-link">{{ .Title }}</a> + </li> + {{ end }} + </ul> + {{ else }} + <p class="recent-empty">暂无文章</p> + {{ end }} +</div> |
