增加文章置顶功能
This commit is contained in:
1 parent
f093cadbb2
commit
2fbc2a1703
1 file changed
+7
-2
@@ -4,18 +4,23 @@
|
||||
<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 }}
|
||||
|
||||
Reference in new issue
Block a user