From d8ec34b724629733128162dc9e3ee7c62f4bc862 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:24:55 +0800 Subject: [PATCH] fix: previous and next post links included hidden posts (#6491) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.19.x #### What this PR does / why we need it: 修复文章的上一篇下一篇链接包含了隐藏分类下的文章 #### Does this PR introduce a user-facing change? ```release-note 修复文章的上一篇下一篇链接包含了隐藏分类下的文章 ``` --- .../app/theme/finders/impl/PostFinderImpl.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/run/halo/app/theme/finders/impl/PostFinderImpl.java b/application/src/main/java/run/halo/app/theme/finders/impl/PostFinderImpl.java index 5316aad0e..e53b5e02e 100644 --- a/application/src/main/java/run/halo/app/theme/finders/impl/PostFinderImpl.java +++ b/application/src/main/java/run/halo/app/theme/finders/impl/PostFinderImpl.java @@ -26,6 +26,7 @@ import run.halo.app.extension.ListResult; import run.halo.app.extension.PageRequestImpl; import run.halo.app.extension.ReactiveExtensionClient; import run.halo.app.extension.exception.ExtensionNotFoundException; +import run.halo.app.extension.index.query.Query; import run.halo.app.extension.index.query.QueryFactory; import run.halo.app.extension.router.selector.FieldSelector; import run.halo.app.extension.router.selector.LabelSelector; @@ -114,6 +115,11 @@ public class PostFinderImpl implements PostFinder { @Override public Mono cursor(String currentName) { return postPredicateResolver.getListOptions() + .map(listOptions -> ListOptions.builder(listOptions) + // Exclude hidden posts + .andQuery(notHiddenPostQuery()) + .build() + ) .flatMap(postListOption -> { var postNames = client.indexedQueryEngine() .retrieve(Post.GVK, postListOption, @@ -136,10 +142,14 @@ public class PostFinderImpl implements PostFinder { .defaultIfEmpty(NavigationPostVo.empty()); } + private static Query notHiddenPostQuery() { + return notEqual("status.hideFromList", BooleanUtils.TRUE); + } + @Override public Mono> list(Integer page, Integer size) { var listOptions = ListOptions.builder() - .fieldQuery(notEqual("status.hideFromList", BooleanUtils.TRUE)) + .fieldQuery(notHiddenPostQuery()) .build(); return postPublicQueryService.list(listOptions, getPageRequest(page, size)); } @@ -207,9 +217,7 @@ public class PostFinderImpl implements PostFinder { public Mono> archives(Integer page, Integer size, String year, String month) { var listOptions = new ListOptions(); - listOptions.setFieldSelector(FieldSelector.of( - notEqual("status.hideFromList", BooleanUtils.TRUE)) - ); + listOptions.setFieldSelector(FieldSelector.of(notHiddenPostQuery())); var labelSelectorBuilder = LabelSelector.builder(); if (StringUtils.isNotBlank(year)) { labelSelectorBuilder.eq(Post.ARCHIVE_YEAR_LABEL, year);