Skip to content

Commit

Permalink
fix: new tags showing null post count on theme (#7049)
Browse files Browse the repository at this point in the history
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
修复新创建的标签在主题端展示关联文章数量为 null 的问题

#### Which issue(s) this PR fixes:

Fixes #7042

#### Does this PR introduce a user-facing change?

```release-note
修复新创建的标签在主题端展示关联文章数量为 null 的问题
```
  • Loading branch information
guqing authored Nov 19, 2024
1 parent 2c8f6f5 commit 7cef55b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ public Result reconcile(Request request) {
String newPattern = tagPermalinkPolicy.pattern();
annotations.put(Constant.PERMALINK_PATTERN_ANNO, newPattern);

String permalink = tagPermalinkPolicy.permalink(tag);
var status = tag.getStatusOrDefault();
String permalink = tagPermalinkPolicy.permalink(tag);
status.setPermalink(permalink);

if (status.getPostCount() == null) {
status.setPostCount(0);
}
if (status.getVisiblePostCount() == null) {
status.setVisiblePostCount(0);
}

// Update the observed version.
status.setObservedVersion(tag.getMetadata().getVersion() + 1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package run.halo.app.theme.finders.vo;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

import lombok.Builder;
import lombok.Value;
import run.halo.app.core.extension.content.Tag;
Expand Down Expand Up @@ -33,7 +35,7 @@ public static TagVo from(Tag tag) {
.metadata(tag.getMetadata())
.spec(spec)
.status(status)
.postCount(tag.getStatusOrDefault().getVisiblePostCount())
.postCount(defaultIfNull(status.getVisiblePostCount(), 0))
.build();
}
}

0 comments on commit 7cef55b

Please sign in to comment.