Skip to content

Commit

Permalink
refactor: add other urls
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Nov 18, 2022
1 parent 8e3fea2 commit f6764a1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Binary file modified lib/halo-2.0.0-SNAPSHOT-plain.jar
Binary file not shown.
36 changes: 35 additions & 1 deletion src/main/java/run/halo/sitemap/DefaultSitemapEntryLister.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package run.halo.sitemap;

import java.util.List;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.Category;
import run.halo.app.core.extension.Post;
import run.halo.app.core.extension.SinglePage;
import run.halo.app.core.extension.Tag;
import run.halo.app.extension.ConfigMap;
import run.halo.app.extension.ExtensionOperator;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.infra.utils.JsonUtils;

@Component
@AllArgsConstructor
Expand All @@ -20,7 +26,9 @@ public class DefaultSitemapEntryLister implements SitemapEntryLister {

@Override
public Flux<SitemapEntry> list() {
return Flux.mergeSequential(listPostUrls(), listCategoryUrls(), listTagUrls(), listSinglePageUrls())
return Flux.mergeSequential(listPostUrls(), listCategoryUrls(), listTagUrls(),
listSinglePageUrls())
.concatWith(urlsForListPages())
.distinct()
.map(options::transform);
}
Expand Down Expand Up @@ -49,4 +57,30 @@ private Flux<String> listTagUrls() {
tag -> tag.getMetadata().getDeletionTimestamp() == null, null)
.map(tag -> tag.getStatusOrDefault().getPermalink());
}

private Flux<String> urlsForListPages() {
// TODO 优化系统其他路由获取
return client.fetch(ConfigMap.class, "system")
.mapNotNull(ConfigMap::getData)
.map(data -> {
String routeRuleConfig = data.get(ThemeRouteRules.GROUP);
ThemeRouteRules themeRouteRules =
JsonUtils.jsonToObject(routeRuleConfig, ThemeRouteRules.class);
return List.of(StringUtils.prependIfMissing(themeRouteRules.getTags(), "/"),
StringUtils.prependIfMissing(themeRouteRules.getCategories(), "/"),
StringUtils.prependIfMissing(themeRouteRules.getArchives(), "/")
);
})
.flatMapMany(Flux::fromIterable);
}

@Data
public static class ThemeRouteRules {
public static final String GROUP = "routeRules";

private String categories;
private String archives;
private String post;
private String tags;
}
}
8 changes: 7 additions & 1 deletion src/main/java/run/halo/sitemap/SitemapPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.halo.app.infra.ExternalUrlSupplier;
import run.halo.app.infra.utils.JsonUtils;
import run.halo.app.plugin.SettingFetcher;

@Component
@AllArgsConstructor
public class SitemapPluginConfig {

private final ExternalUrlSupplier externalUrlSupplier;

@Bean
Expand Down

0 comments on commit f6764a1

Please sign in to comment.