增加文章置顶功能

This commit is contained in:
小赵同学 committed 2024-09-19 23:27:24 +08:00
1 parent e5498ce327
commit c174d3650a
1 file changed
+8 -3
+8 -3
View File
@@ -4,24 +4,29 @@
<div class="recent-posts section">
<h2 class="section-header">随笔<i class="ri-quill-pen-line"></i></h2>
<div class="posts">
{{ $paginator := .Paginate (where (where .Site.RegularPages "Type" "post") "Params.status" "ne" "hidden") }}
<!-- 使用 ByWeight 来排序 -->
{{ $posts := where (where .Site.RegularPages "Type" "post") "Params.status" "ne" "hidden" | sort "Weight" "asc" }}
{{ $paginator := .Paginate $posts }}
{{ range $paginator.Pages }}
<div class="post">
<div class="time">{{ .Date.Format "January 2, 2006" }}</div>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<!-- 计算每篇文章的发布时间与当前时间的差值 -->
{{ $publishDate := .Date }}
{{ $currentTime := now }}
{{ $timeDiff := div (sub $currentTime.Unix $publishDate.Unix) 3600 }}
<!-- 判断发布时间是否小于 24 小时 -->
{{ if lt $timeDiff 24 }}
<span class="new-post-message"></span>
<span class="new-post-message">New</span>
{{ end }}
</div>
{{ end }}
</div>
</div>
</article>
</article>
<ul class="pagination">
<li class="page-item page-next">
{{ if $paginator.HasNext }}