diff --git a/application/src/main/java/run/halo/app/core/reconciler/PostReconciler.java b/application/src/main/java/run/halo/app/core/reconciler/PostReconciler.java index 056beffc9..11c25a8cc 100644 --- a/application/src/main/java/run/halo/app/core/reconciler/PostReconciler.java +++ b/application/src/main/java/run/halo/app/core/reconciler/PostReconciler.java @@ -388,6 +388,10 @@ public class PostReconciler implements Reconciler { } var content = contentWrapper.get(); + if (StringUtils.isAnyBlank(content.getContent(), content.getRaw())) { + return StringUtils.EMPTY; + } + var contentChecksum = Hashing.sha256().hashString(content.getContent(), UTF_8).toString(); var annotations = MetadataUtil.nullSafeAnnotations(post); var oldChecksum = annotations.get(Constant.CONTENT_CHECKSUM_ANNO); diff --git a/application/src/test/java/run/halo/app/core/reconciler/PostReconcilerTest.java b/application/src/test/java/run/halo/app/core/reconciler/PostReconcilerTest.java index 3dd75e516..35f1c7ede 100644 --- a/application/src/test/java/run/halo/app/core/reconciler/PostReconcilerTest.java +++ b/application/src/test/java/run/halo/app/core/reconciler/PostReconcilerTest.java @@ -106,6 +106,42 @@ class PostReconcilerTest { assertThat(value.getStatus().getContributors()).isEqualTo(List.of("guqing", "zhangsan")); } + @Test + void shouldGenerateBlankExcerptWhenContentIsNull() { + var name = "post-A"; + Post post = TestPost.postV1(); + post.getSpec().setPublish(true); + post.getSpec().setHeadSnapshot("post-A-head-snapshot"); + post.getSpec().setReleaseSnapshot("post-fake-released-snapshot"); + when(client.fetch(eq(Post.class), eq(name))) + .thenReturn(Optional.of(post)); + when(postService.getContent(eq(post.getSpec().getReleaseSnapshot()), + eq(post.getSpec().getBaseSnapshot()))) + .thenReturn(Mono.just(ContentWrapper.builder() + .snapshotName(post.getSpec().getHeadSnapshot()) + .raw(null) + .content(null) + .rawType("markdown") + .build())); + + Snapshot snapshotV2 = TestPost.snapshotV2(); + snapshotV2.getMetadata().setLabels(new HashMap<>()); + snapshotV2.getSpec().setContributors(Set.of("guqing", "zhangsan")); + + Snapshot snapshotV1 = TestPost.snapshotV1(); + snapshotV1.getSpec().setContributors(Set.of("guqing")); + + when(client.listAll(eq(Snapshot.class), any(), any())) + .thenReturn(List.of(snapshotV1, snapshotV2)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(Post.class); + postReconciler.reconcile(new Reconciler.Request(name)); + + verify(client, times(1)).update(captor.capture()); + Post value = captor.getValue(); + assertThat(value.getStatus().getExcerpt()).isEqualTo(""); + } + @Test void reconcileExcerpt() { // https://github.com/halo-dev/halo/issues/2452