mirror of https://github.com/halo-dev/halo
refactor: autofill if post is published but no publish time (#4775)
#### What type of PR is this? /kind improvement /area core /milestone 2.10.x #### What this PR does / why we need it: 如果文章是发布状态但没有发布时间则自动填充 #### Does this PR introduce a user-facing change? ```release-note None ```pull/4785/head
parent
3905ec8b8d
commit
b5094d6e6f
|
@ -113,6 +113,10 @@ public class PostReconciler implements Reconciler<Reconciler.Request> {
|
|||
post.setStatus(status);
|
||||
}
|
||||
|
||||
if (post.isPublished() && post.getSpec().getPublishTime() == null) {
|
||||
post.getSpec().setPublishTime(Instant.now());
|
||||
}
|
||||
|
||||
// calculate the sha256sum
|
||||
var configSha256sum = Hashing.sha256().hashString(post.getSpec().toString(), UTF_8)
|
||||
.toString();
|
||||
|
|
|
@ -112,6 +112,10 @@ public class SinglePageReconciler implements Reconciler<Reconciler.Request> {
|
|||
|
||||
private void reconcileSpec(String name) {
|
||||
client.fetch(SinglePage.class, name).ifPresent(page -> {
|
||||
if (page.isPublished() && page.getSpec().getPublishTime() == null) {
|
||||
page.getSpec().setPublishTime(Instant.now());
|
||||
}
|
||||
|
||||
// un-publish if necessary
|
||||
if (page.isPublished() && Objects.equals(false, page.getSpec().getPublish())) {
|
||||
unPublish(name);
|
||||
|
|
Loading…
Reference in New Issue