Skip to content

Commit 60f79ee

Browse files
authored
fix: 修复文章数量显示逻辑 (#26)
- 在分类和标签相关的模板中,使用 Elvis 操作符(?:)来处理可见文章数量 - 当 visiblePostCount 为 null 时,显示为 0,避免出现空白或错误的数字 - 修改涉及 category.html、category-tree.html、tag.html 和 tags.html 四个模板文件
1 parent 9a901b7 commit 60f79ee

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

templates/category.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="post">
99
<h1
1010
class="post-title"
11-
th:text="'分类:'+${category.spec.displayName}+' ('+${category.status.visiblePostCount}+' 篇文章)'"
11+
th:text="'分类:'+${category.spec.displayName}+' ('+${category.status.visiblePostCount?:0}+' 篇文章)'"
1212
>
1313
分类:分类名 (n 篇文章)
1414
</h1>

templates/modules/category-tree.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ul th:fragment="next (categories)">
22
<li th:fragment="single (categories)" th:each="category : ${categories}">
33
<a th:href="@{${category.status.permalink}}">
4-
<span th:text="${category.spec.displayName}+' ('+${category.status.visiblePostCount}+' 篇文章)'"> </span>
4+
<span th:text="${category.spec.displayName}+' ('+${category.status.visiblePostCount?:0}+' 篇文章)'"> </span>
55
</a>
66
<th:block th:if="${not #lists.isEmpty(category.children)}">
77
<th:block th:replace="~{modules/category-tree :: next (categories=${category.children})}"></th:block>

templates/tag.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="post">
99
<h1
1010
class="post-title"
11-
th:text="'标签:'+${tag.spec.displayName}+' ('+${tag.status.visiblePostCount}+' 篇文章)'"
11+
th:text="'标签:'+${tag.spec.displayName}+' ('+${tag.status.visiblePostCount?:0}+' 篇文章)'"
1212
>
1313
标签:标签名 (n 篇文章)
1414
</h1>

templates/tags.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1 class="post-title">所有标签</h1>
1111
<li th:each="tag: ${tags}" class="tag-list">
1212
<a
1313
th:href="@{${tag.status.permalink}}"
14-
th:text="${tag.spec.displayName}+' ('+${tag.status.visiblePostCount}+' 篇文章)'"
14+
th:text="${tag.spec.displayName}+' ('+${tag.status.visiblePostCount?:0}+' 篇文章)'"
1515
>
1616
标签名 (n 篇文章)
1717
</a>

0 commit comments

Comments
 (0)