From 11407c29acaeccf4c6295ed24b08b7887d17f25d Mon Sep 17 00:00:00 2001 From: guqing <1484563614@qq.com> Date: Fri, 6 Dec 2024 17:38:16 +0800 Subject: [PATCH] refactor: add extension point definition --- app/src/main/java/run/halo/feed/RssXmlBuilder.java | 2 +- .../run/halo/feed/telemetry/TelemetryEndpoint.java | 13 ++++++++++--- app/src/main/resources/1pixel.png | Bin 0 -> 68 bytes .../main/resources/extensions/ext-definition.yaml | 11 +++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 app/src/main/resources/1pixel.png diff --git a/app/src/main/java/run/halo/feed/RssXmlBuilder.java b/app/src/main/java/run/halo/feed/RssXmlBuilder.java index 8e7ce1f..01f714d 100644 --- a/app/src/main/java/run/halo/feed/RssXmlBuilder.java +++ b/app/src/main/java/run/halo/feed/RssXmlBuilder.java @@ -232,7 +232,7 @@ private String getDescriptionWithTelemetry(RSS2.Item item) { ); // Append telemetry image to description - return item.getDescription() + telemetryImageHtml; + return telemetryImageHtml + item.getDescription(); } static List nullSafeList(List list) { diff --git a/app/src/main/java/run/halo/feed/telemetry/TelemetryEndpoint.java b/app/src/main/java/run/halo/feed/telemetry/TelemetryEndpoint.java index c75b5e3..1a71538 100644 --- a/app/src/main/java/run/halo/feed/telemetry/TelemetryEndpoint.java +++ b/app/src/main/java/run/halo/feed/telemetry/TelemetryEndpoint.java @@ -2,6 +2,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -16,10 +18,15 @@ @RequiredArgsConstructor public class TelemetryEndpoint { public static final String TELEMETRY_PATH = "/plugins/feed/assets/telemetry.gif"; - static final String ONE_PIXEL_GIF_BASE64 = - "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; + static final Resource ONE_PIXEL; private final TelemetryRecorderDelegator telemetryRecorderDelegator; + static { + // RSS readers may thumbnail images, and using base64 images may cause RSS readers to + // fail to parse correctly. + ONE_PIXEL = new ClassPathResource("1pixel.png", TelemetryEndpoint.class.getClassLoader()); + } + @Bean public RouterFunction telemetryImageRouter() { return RouterFunctions.route() @@ -28,7 +35,7 @@ public RouterFunction telemetryImageRouter() { return ServerResponse.ok() .header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_GIF_VALUE) .cacheControl(CacheControl.noCache()) - .bodyValue(ONE_PIXEL_GIF_BASE64); + .bodyValue(ONE_PIXEL); }) .build(); } diff --git a/app/src/main/resources/1pixel.png b/app/src/main/resources/1pixel.png new file mode 100644 index 0000000000000000000000000000000000000000..909c66db1740b7c1b41eb4db6c414a7ab5bb6a23 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcwN$DG5Lh8v~O;;{|;n Oi^0>?&t;ucLK6U5DhwL{ literal 0 HcmV?d00001 diff --git a/app/src/main/resources/extensions/ext-definition.yaml b/app/src/main/resources/extensions/ext-definition.yaml index cb4211f..e587a7c 100644 --- a/app/src/main/resources/extensions/ext-definition.yaml +++ b/app/src/main/resources/extensions/ext-definition.yaml @@ -10,6 +10,17 @@ spec: icon: "/plugins/PluginFeed/assets/logo.svg" --- apiVersion: plugin.halo.run/v1alpha1 +kind: ExtensionPointDefinition +metadata: + name: feed-telemetry-recorder +spec: + className: run.halo.feed.TelemetryRecorder + displayName: "遥测内容访问量记录器" + description: "用于扩展 RSS 内容访问量的存储方式,如上报到 Umami" + type: MULTI_INSTANCE + icon: "/plugins/PluginFeed/assets/logo.svg" +--- +apiVersion: plugin.halo.run/v1alpha1 kind: ExtensionDefinition metadata: name: feed-category-post-rss-item