From ccf761b77da0d297ef4072b20132c3e180fc245b Mon Sep 17 00:00:00 2001 From: guqing Date: Fri, 27 Oct 2023 11:18:16 +0800 Subject: [PATCH] refactor: autofill if post is published but no publish time --- .../halo/app/core/extension/reconciler/PostReconciler.java | 4 ++++ .../app/core/extension/reconciler/SinglePageReconciler.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java index eb182a51a7..fafdd67a2c 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java @@ -113,6 +113,10 @@ public Result reconcile(Request 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(); diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java index 441d95dae6..ad46213b5e 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java @@ -112,6 +112,10 @@ void subscribeNewCommentNotification(SinglePage page) { 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);