Skip to content

Commit

Permalink
fix: incorrect domain of loc in sitemap url entry (#25)
Browse files Browse the repository at this point in the history
### What this PR does?
修复 sitemap 中的 loc 的域名不正确问题

Fixes #13, #11

```release-note
修复 sitemap 中的 loc 的域名不正确问题
```
  • Loading branch information
guqing authored Sep 25, 2023
1 parent 4ebd330 commit b3f00e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jar {
}

dependencies {
implementation platform('run.halo.tools.platform:plugin:2.5.0-SNAPSHOT')
implementation platform('run.halo.tools.platform:plugin:2.9.0-SNAPSHOT')
compileOnly 'run.halo.app:api'

testImplementation 'run.halo.app:api'
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/run/halo/sitemap/SitemapPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

import java.net.MalformedURLException;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
Expand All @@ -13,7 +12,6 @@
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.Exceptions;
import run.halo.app.infra.ExternalUrlSupplier;
import run.halo.app.plugin.ReactiveSettingFetcher;

Expand All @@ -31,18 +29,13 @@ public class SitemapPluginConfig {
RouterFunction<ServerResponse> sitemapRouterFunction(CachedSitemapGetter cachedSitemapGetter) {
return RouterFunctions.route(GET("/sitemap.xml")
.and(accept(MediaType.TEXT_XML)), request -> {
var uri = externalUrlSupplier.get();
if (!uri.isAbsolute()) {
uri = request.exchange().getRequest().getURI().resolve(uri);
}
SitemapGeneratorOptions options;
try {
options = SitemapGeneratorOptions.builder()
.siteUrl(uri.toURL())
.build();
} catch (MalformedURLException e) {
throw Exceptions.propagate(e);
var url = externalUrlSupplier.getRaw();
if (url == null) {
url = externalUrlSupplier.getURL(request.exchange().getRequest());
}
var options = SitemapGeneratorOptions.builder()
.siteUrl(url)
.build();
return cachedSitemapGetter.get(options)
.flatMap(sitemap -> ServerResponse.ok()
.contentType(MediaType.TEXT_XML).bodyValue(sitemap));
Expand Down

0 comments on commit b3f00e8

Please sign in to comment.