|
4 | 4 | import java.util.Comparator; |
5 | 5 | import java.util.List; |
6 | 6 | import java.util.Objects; |
| 7 | +import java.util.Optional; |
7 | 8 | import java.util.function.Function; |
8 | 9 | import lombok.AllArgsConstructor; |
9 | | -import lombok.Data; |
10 | 10 | import org.apache.commons.lang3.StringUtils; |
| 11 | +import org.apache.commons.lang3.Strings; |
11 | 12 | import org.springframework.stereotype.Component; |
12 | 13 | import reactor.core.publisher.Flux; |
13 | 14 | import run.halo.app.core.extension.content.Category; |
|
17 | 18 | import run.halo.app.extension.ConfigMap; |
18 | 19 | import run.halo.app.extension.ExtensionOperator; |
19 | 20 | import run.halo.app.extension.ReactiveExtensionClient; |
| 21 | +import run.halo.app.infra.SystemSetting; |
| 22 | +import run.halo.app.infra.SystemSetting.ThemeRouteRules; |
20 | 23 | import run.halo.app.infra.utils.JsonUtils; |
21 | 24 |
|
22 | 25 | @Component |
@@ -89,28 +92,20 @@ private Flux<UrlEntryMeta> listTagUrls() { |
89 | 92 |
|
90 | 93 | private Flux<UrlEntryMeta> urlsForListPages() { |
91 | 94 | // TODO 优化系统其他路由获取 |
92 | | - return client.fetch(ConfigMap.class, "system") |
| 95 | + return client.fetch(ConfigMap.class, SystemSetting.SYSTEM_CONFIG) |
93 | 96 | .mapNotNull(ConfigMap::getData) |
94 | 97 | .map(data -> { |
95 | | - String routeRuleConfig = data.get(ThemeRouteRules.GROUP); |
96 | | - ThemeRouteRules themeRouteRules = |
97 | | - JsonUtils.jsonToObject(routeRuleConfig, ThemeRouteRules.class); |
98 | | - return List.of(StringUtils.prependIfMissing(themeRouteRules.getTags(), "/"), |
99 | | - StringUtils.prependIfMissing(themeRouteRules.getCategories(), "/"), |
100 | | - StringUtils.prependIfMissing(themeRouteRules.getArchives(), "/") |
| 98 | + var themeRouteRules = Optional.ofNullable(data.get(ThemeRouteRules.GROUP)) |
| 99 | + .filter(StringUtils::isNotBlank) |
| 100 | + .map(json -> JsonUtils.jsonToObject(json, ThemeRouteRules.class)) |
| 101 | + .orElseGet(ThemeRouteRules::empty); |
| 102 | + return List.of(Strings.CS.prependIfMissing(themeRouteRules.getTags(), "/"), |
| 103 | + Strings.CS.prependIfMissing(themeRouteRules.getCategories(), "/"), |
| 104 | + Strings.CS.prependIfMissing(themeRouteRules.getArchives(), "/") |
101 | 105 | ); |
102 | 106 | }) |
103 | 107 | .flatMapMany(Flux::fromIterable) |
104 | 108 | .map(url -> new UrlEntryMeta(url).setPriority(0.5)); |
105 | 109 | } |
106 | 110 |
|
107 | | - @Data |
108 | | - public static class ThemeRouteRules { |
109 | | - public static final String GROUP = "routeRules"; |
110 | | - |
111 | | - private String categories; |
112 | | - private String archives; |
113 | | - private String post; |
114 | | - private String tags; |
115 | | - } |
116 | 111 | } |
0 commit comments