mirror of https://github.com/halo-dev/halo
fix: post excerptare generated using only published content that is in use (#2457)
#### What type of PR is this? /kind improvement /area core /milestone 2.0 #### What this PR does / why we need it: 文章自动摘要只从正在使用的已发布版本的内容中取得 #### Which issue(s) this PR fixes: Fixes #2452 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note None ```pull/2471/head
parent
ed8dddbafa
commit
721cddff5d
|
@ -109,7 +109,7 @@ public class PostReconciler implements Reconciler<Reconciler.Request> {
|
|||
spec.setExcerpt(excerpt);
|
||||
}
|
||||
if (excerpt.getAutoGenerate()) {
|
||||
contentService.getContent(spec.getHeadSnapshot())
|
||||
contentService.getContent(spec.getReleaseSnapshot())
|
||||
.subscribe(content -> {
|
||||
String contentRevised = content.content();
|
||||
status.setExcerpt(getExcerpt(contentRevised));
|
||||
|
|
|
@ -7,6 +7,7 @@ import static org.mockito.Mockito.times;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
@ -54,10 +55,8 @@ class PostReconcilerTest {
|
|||
post.getSpec().setHeadSnapshot("post-A-head-snapshot");
|
||||
when(client.fetch(eq(Post.class), eq(name)))
|
||||
.thenReturn(Optional.of(post));
|
||||
when(contentService.getContent(eq(post.getSpec().getHeadSnapshot())))
|
||||
.thenReturn(Mono.just(
|
||||
new ContentWrapper(post.getSpec().getHeadSnapshot(), "hello world",
|
||||
"<p>hello world</p>", "markdown")));
|
||||
when(contentService.getContent(eq(post.getSpec().getReleaseSnapshot())))
|
||||
.thenReturn(Mono.empty());
|
||||
|
||||
Snapshot snapshotV1 = TestPost.snapshotV1();
|
||||
Snapshot snapshotV2 = TestPost.snapshotV2();
|
||||
|
@ -77,8 +76,39 @@ class PostReconcilerTest {
|
|||
verify(postPermalinkPolicy, times(0)).onPermalinkUpdate(any());
|
||||
|
||||
Post value = captor.getValue();
|
||||
assertThat(value.getStatus().getExcerpt()).isEqualTo("hello world");
|
||||
assertThat(value.getStatus().getExcerpt()).isNull();
|
||||
assertThat(value.getStatus().getContributors()).isEqualTo(List.of("guqing", "zhangsan"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reconcileExcerpt() {
|
||||
// https://github.com/halo-dev/halo/issues/2452
|
||||
String name = "post-A";
|
||||
Post post = TestPost.postV1();
|
||||
post.getSpec().setPublished(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(contentService.getContent(eq(post.getSpec().getReleaseSnapshot())))
|
||||
.thenReturn(Mono.just(
|
||||
new ContentWrapper(post.getSpec().getHeadSnapshot(), "hello world",
|
||||
"<p>hello world</p>", "markdown")));
|
||||
|
||||
Snapshot snapshotV1 = TestPost.snapshotV1();
|
||||
Snapshot snapshotV2 = TestPost.snapshotV2();
|
||||
snapshotV2.getSpec().setPublishTime(Instant.now());
|
||||
snapshotV1.getSpec().setContributors(Set.of("guqing"));
|
||||
snapshotV2.getSpec().setContributors(Set.of("guqing", "zhangsan"));
|
||||
when(contentService.listSnapshots(any()))
|
||||
.thenReturn(Flux.just(snapshotV1, snapshotV2));
|
||||
|
||||
ArgumentCaptor<Post> captor = ArgumentCaptor.forClass(Post.class);
|
||||
postReconciler.reconcile(new Reconciler.Request(name));
|
||||
|
||||
verify(client, times(3)).update(captor.capture());
|
||||
Post value = captor.getValue();
|
||||
assertThat(value.getStatus().getExcerpt()).isEqualTo("hello world");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue