improve the sorting rules for themes side posts using publishTime (#3148)

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?
/kind improvement
/area core
<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind improvement

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:
Provide administrators with the ability to adjust the order of articles by modifying the publish time.

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

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes https://github.com/halo-dev/halo/issues/3143

#### Special notes for your reviewer:
修改前:
![image](https://user-images.githubusercontent.com/28662535/212074405-e0a351fe-9293-4a4f-af9c-41f720512f9b.png)
修改后:
![image](https://user-images.githubusercontent.com/28662535/212074498-1091bb62-700e-4e1f-872a-46687cdbd81c.png)

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

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
主题侧文章以发布时间排序
```
pull/3152/head^2
longjuan 2023-01-16 10:54:13 +08:00 committed by GitHub
parent d6ff0fd83c
commit 575fc95876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -373,12 +373,12 @@ public class PostFinderImpl implements PostFinder {
post -> Objects.requireNonNullElse(post.getSpec().getPinned(), false);
Function<Post, Integer> priority =
post -> Objects.requireNonNullElse(post.getSpec().getPriority(), 0);
Function<Post, Instant> creationTimestamp =
post -> post.getMetadata().getCreationTimestamp();
Function<Post, Instant> publishTime =
post -> post.getSpec().getPublishTime();
Function<Post, String> name = post -> post.getMetadata().getName();
return Comparator.comparing(pinned)
.thenComparing(priority)
.thenComparing(creationTimestamp)
.thenComparing(publishTime, Comparators.nullsLow())
.thenComparing(name)
.reversed();
}

View File

@ -193,35 +193,35 @@ class PostFinderImplTest {
List<Post> posts() {
// 置顶的排前面按 priority 排序
// 再根据创建时间排序
// 再根据发布时间排序
// 相同再根据名称排序
// 6, 2, 1, 5, 4, 3
Post post1 = post(1);
post1.getSpec().setPinned(false);
post1.getMetadata().setCreationTimestamp(Instant.now().plusSeconds(20));
post1.getSpec().setPublishTime(Instant.now().plusSeconds(20));
Post post2 = post(2);
post2.getSpec().setPinned(true);
post2.getSpec().setPriority(2);
post2.getMetadata().setCreationTimestamp(Instant.now());
post2.getSpec().setPublishTime(Instant.now());
Post post3 = post(3);
post3.getSpec().setDeleted(true);
post3.getMetadata().setCreationTimestamp(Instant.now());
post3.getSpec().setPublishTime(Instant.now());
Post post4 = post(4);
post4.getSpec().setVisible(Post.VisibleEnum.PRIVATE);
post4.getMetadata().setCreationTimestamp(Instant.now());
post4.getSpec().setPublishTime(Instant.now());
Post post5 = post(5);
post5.getSpec().setPublish(false);
post5.getMetadata().getLabels().clear();
post5.getMetadata().setCreationTimestamp(Instant.now());
post5.getSpec().setPublishTime(Instant.now());
Post post6 = post(6);
post6.getSpec().setPinned(true);
post6.getSpec().setPriority(3);
post6.getMetadata().setCreationTimestamp(Instant.now());
post6.getSpec().setPublishTime(Instant.now());
return List.of(post1, post2, post3, post4, post5, post6);
}