diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index e83fa03..e7d8d21 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -15,5 +15,7 @@ jobs: contents: write with: app-id: app-KhIVw - skip-node-setup: true + node-version: "20" + pnpm-version: "9" + ui-path: "ui" artifacts-path: 'app/build/libs' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fec1287..34dc5ff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,5 +12,7 @@ jobs: ci: uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v1 with: - skip-node-setup: true + node-version: "20" + pnpm-version: "9" + ui-path: "ui" artifacts-path: 'app/build/libs' diff --git a/app/src/main/java/run/halo/feed/FeedPluginEndpoint.java b/app/src/main/java/run/halo/feed/FeedPluginEndpoint.java index c1f6689..5b79b79 100644 --- a/app/src/main/java/run/halo/feed/FeedPluginEndpoint.java +++ b/app/src/main/java/run/halo/feed/FeedPluginEndpoint.java @@ -16,6 +16,8 @@ import run.halo.app.plugin.extensionpoint.ExtensionGetter; import run.halo.feed.provider.PostRssProvider; +import java.util.ArrayList; + import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import static org.springframework.web.reactive.function.server.RequestPredicates.path; @@ -23,8 +25,8 @@ @AllArgsConstructor public class FeedPluginEndpoint { static final RequestPredicate ACCEPT_PREDICATE = accept( - MediaType.TEXT_XML, - MediaType.APPLICATION_RSS_XML + MediaType.TEXT_XML, + MediaType.APPLICATION_RSS_XML ); private final PostRssProvider postRssProvider; @@ -35,35 +37,46 @@ public class FeedPluginEndpoint { @Bean RouterFunction rssRouterFunction() { return RouterFunctions.route() - .GET(path("/feed.xml").or(path("/rss.xml")).and(ACCEPT_PREDICATE), - request -> rssCacheManager.get("/rss.xml", postRssProvider.handler(request)) - .flatMap(this::buildResponse) - ) - .build(); + .GET(path("/feed.xml").or(path("/rss.xml")).and(ACCEPT_PREDICATE), + request -> rssCacheManager.get("/rss.xml", postRssProvider.handler(request)) + .flatMap(this::buildResponse) + ) + .build(); } @Bean RouterFunction rssSourcesListerRouter() { return RouterFunctions.route() - .GET("/apis/api.feed.halo.run/v1alpha1/rss-sources", this::listRssSources) - .build(); + .GET("/apis/api.feed.halo.run/v1alpha1/rss-sources", this::listRssSources) + .build(); } private Mono listRssSources(ServerRequest request) { var externalUrl = externalUrlSupplier.getURL(request.exchange().getRequest()).toString(); return extensionGetter.getEnabledExtensions(RssRouteItem.class) - .concatMap(item -> { - var rssSource = RssSource.builder() - .displayName(item.displayName()) - .description(item.description()) - .example(item.example()); - return item.pathPattern() - .map(pattern -> buildPathPattern(pattern, item.namespace())) - .doOnNext(path -> rssSource.pattern(externalUrl + path)) - .then(Mono.fromSupplier(rssSource::build)); - }) - .collectList() - .flatMap(ServerResponse.ok()::bodyValue); + .concatMap(item -> { + var rssSource = RssSource.builder() + .displayName(item.displayName()) + .description(item.description()) + .example(item.example()); + return item.pathPattern() + .map(pattern -> buildPathPattern(pattern, item.namespace())) + .doOnNext(path -> rssSource.pattern(externalUrl + path)) + .then(Mono.fromSupplier(rssSource::build)); + }) + .collectList() + .flatMap(result -> { + var allPosts = RssSource.builder() + .pattern(externalUrl + "/rss.xml") + .displayName("订阅所有文章") + .description("会根据设置的文章数量返回最新的文章") + .example("https://example.com/rss.xml") + .build(); + var sources = new ArrayList<>(); + sources.add(allPosts); + sources.addAll(result); + return ServerResponse.ok().bodyValue(sources); + }); } @Builder @@ -78,20 +91,20 @@ RouterFunction additionalRssRouter() { @NonNull public Mono> route(@NonNull ServerRequest request) { return pathMatcher.matches(request.exchange()) - .filter(ServerWebExchangeMatcher.MatchResult::isMatch) - .flatMap(matched -> handleRequest(request)); + .filter(ServerWebExchangeMatcher.MatchResult::isMatch) + .flatMap(matched -> handleRequest(request)); } private Mono> handleRequest(ServerRequest request) { return extensionGetter.getEnabledExtensions(RssRouteItem.class) - .concatMap(routeItem -> buildRequestPredicate(routeItem) - .map(requestPredicate -> new RouteItem(requestPredicate, - buildHandleFunction(routeItem)) - ) + .concatMap(routeItem -> buildRequestPredicate(routeItem) + .map(requestPredicate -> new RouteItem(requestPredicate, + buildHandleFunction(routeItem)) ) - .filter(route -> route.requestPredicate.test(request)) - .next() - .map(RouteItem::handler); + ) + .filter(route -> route.requestPredicate.test(request)) + .next() + .map(RouteItem::handler); } record RouteItem(RequestPredicate requestPredicate, @@ -100,15 +113,15 @@ record RouteItem(RequestPredicate requestPredicate, private HandlerFunction buildHandleFunction(RssRouteItem routeItem) { return request -> rssCacheManager.get(request.path(), routeItem.handler(request)) - .flatMap(item -> buildResponse(item)); + .flatMap(item -> buildResponse(item)); } private Mono buildRequestPredicate(RssRouteItem routeItem) { return routeItem.pathPattern() - .map(pathPattern -> path( - buildPathPattern(pathPattern, routeItem.namespace())) - .and(ACCEPT_PREDICATE) - ); + .map(pathPattern -> path( + buildPathPattern(pathPattern, routeItem.namespace())) + .and(ACCEPT_PREDICATE) + ); } }; } @@ -133,6 +146,6 @@ private String buildPathPattern(String pathPattern, String namespace) { private Mono buildResponse(String xml) { return ServerResponse.ok().contentType(MediaType.TEXT_XML) - .bodyValue(xml); + .bodyValue(xml); } }