GithubHelp home page GithubHelp logo

halo-dev / plugin-feed Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 7.0 1.83 MB

Halo 2.0 的 RSS 订阅链接生成插件

Home Page: https://halo.run/store/apps/app-KhIVw

License: GNU General Public License v3.0

Java 100.00%
halo halo-plugin

plugin-feed's Introduction

plugin-feed

Halo 2.0 的 RSS 订阅链接生成插件

开发环境

git clone [email protected]:halo-dev/plugin-feed.git

# 或者当你 fork 之后

git clone [email protected]:{your_github_id}/plugin-feed.git
cd path/to/plugin-feed
# macOS / Linux
./gradlew build

# Windows
./gradlew.bat build

修改 Halo 配置文件:

halo:
  plugin:
    runtime-mode: development
    classes-directories:
      - "build/classes"
      - "build/resources"
    lib-directories:
      - "libs"
    fixedPluginPath:
      - "/path/to/plugin-feed"

使用方式

  1. Releases 下载最新的 JAR 文件。
  2. 在 Halo 后台的插件管理上传 JAR 文件进行安装。

目前提供了以下订阅链接类型:

  1. 全站订阅:/feed.xml 或者 /rss.xml
  2. 按照分类订阅(可以在插件设置中关闭):/feed/categories/{slug}.xml
  3. 按照作者订阅(可以在插件设置中关闭):/feed/authors/{name}.xml

plugin-feed's People

Contributors

ftl1ght avatar hllshiro avatar johnniang avatar longjuan avatar ruibaby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

plugin-feed's Issues

feed 插件的功能要求

功能要求

  1. 插件需要注册 /feed.xml 或者 /rss.xml 的路由以输出最近的文章更新。
  2. 需要支持针对单个分类的订阅链接,比如 /feed/categories/halo.xml,即只输出 halo 分类下的文章更新。
  3. 需要支持针对单个作者的订阅链接,比如 /feed/authors/ryanwang.xml,即只输出作者为 ryanwang 的文章更新。
  4. 需要提供以下配置项:
    1. 是否开启单个分类的订阅链接。
    2. 是否开启单个作者的订阅链接。
    3. 内容输出类型:全文(即 post.spec.content)或者摘要(即 post.status.excerpt)。
    4. 内容输出条数。

【bug】rss信息的Item对象中,link属性externalUrl重复

Hi~下面是请求的结果,可以看到,Item的link属性,externalUrl重复出现

<rss version="2.0">
    <channel>
        <title>note</title>
        <link>https://halo.xxx.cn:9443/</link>
        <description>note</description>
        <item>
            <title>
                <![CDATA[ Hello Halo ]]>
            </title>
            <link>https://halo.xxx.cn:9443/https://halo.xxx.cn:9443/archives/hello-halo</link>
            <description>
                <![CDATA[ 如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 Halo 进行创作,希望能够使用愉快。 ]]>
            </description>
            <guid>/archives/hello-halo</guid>
            <pubDate>Sat, 7 Oct 2023 03:19:04 GMT</pubDate>
        </item>
    </channel>
</rss>

查看了生成Item的代码,发现在判断permalinkUri不是绝对路径后,通过externalUrl重新解析permalinkUri来生成绝对路径url。但是在itemBuilder中再次拼接了externalUrl

private Mono<ServerResponse> postListResultToXmlServerResponse(
        Mono<ListResult<Post>> postListResult,
        FeedContext feedContext, RSS2 rss2) {
        return postListResult
            .flatMapIterable(ListResult::getItems)
            .flatMap(post -> {
                // Create item
                var permalink = post.getStatusOrDefault().getPermalink();
                if (permalink != null) {
                    var permalinkUri = URI.create(permalink);
                    if (!permalinkUri.isAbsolute()) {
                        try {
                            // 此处将相对路径转为了绝对路径
                            permalinkUri = feedContext.externalUrl.toURI().resolve(permalinkUri);
                        } catch (URISyntaxException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    permalink = permalinkUri.toString();
                }
                var itemBuilder = RSS2.Item.builder()
                    .title(post.getSpec().getTitle())
                    // 此处再次拼接了服务器externalUrl
                    .link(feedContext.externalUrl.toString() + permalink)
                    .pubDate(post.getSpec().getPublishTime())
                    .guid(post.getStatusOrDefault().getPermalink());

                // TODO lastBuildDate need upgrade halo dependency version

                // Set description
    }

/kind bug

什么时候发版

这个插件没有发版哇,现在可以正常使用么,想用😻

【bug】rss-parse请求404错误

node的rss-parse库在发送请求前会追加默认header,请求会返回404错误。经过测试,主要是因为Accept头导致此错误。

const DEFAULT_HEADERS = {
  'User-Agent': 'rss-parser',
  'Accept': 'application/rss+xml',
}

修复后的代码如下:
FeedPluginEndpoint.java

    @Bean
    RouterFunction<ServerResponse> sitemapRouterFunction() {
        return RouterFunctions.route(GET("/feed.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
                feedService::allFeed)
            .andRoute(GET("/rss.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
                feedService::allFeed)
            .andRoute(GET("/feed/categories/{category}.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
                request -> feedService.categoryFeed(request, request.pathVariable("category")))
            .andRoute(GET("/feed/authors/{author}.xml").and(accept(MediaType.TEXT_XML, MediaType.APPLICATION_RSS_XML)),
                request -> feedService.authorFeed(request, request.pathVariable("author")));
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.