1个不稳定版本
0.0.5 | 2024年2月20日 |
---|
#32 在 #feed
140KB
4.5K SLoC
- RSS Funnel
RSS Funnel是一个模块化的RSS处理管道。它设计用于以各种有趣的方式修改现有的RSS源,例如
- 获取完整内容
- 从HTML页面生成RSS源
- 从文章中移除不需要的元素(使用CSS选择器)
- 保留或删除匹配关键字或模式的文章
- 在文章中突出显示关键字
- 使用正则表达式对文章中的文本进行编辑或替换
- 将单个RSS文章拆分为多个文章
- 将多个源合并为一个源
- 运行任意JS代码以转换源或文章(支持[[https://github.com/shouya/rss-funnel/wiki/JS-DOM-API][DOM API]])
[[https://rss-funnel-demo.fly.dev/][尝试实时演示!]]
** 安装
您可以在您的 =docker-compose.yaml= 中使用docker镜像 ([[https://github.com/shouya/rss-funnel/pkgs/container/rss-funnel][最新版本]])
#+begin_src yaml version: "3.8" services: rss-funnel: image: ghcr.io/shouya/rss-funnel:latest ports: - 4080:4080 volumes: - ./funnel.yaml:/funnel.yaml command: /rss-funnel -c /funnel.yaml server -b 0.0.0.0:4080 #+end_src
或者,您可以直接从源代码构建
#+begin_src bash git clone https://github.com/shouya/rss-funnel.git cd rss-funnel
首先构建前端资源
cd inspector && npm i && npm run build && cd ..
然后构建二进制文件
cargo build --release #+end_src
或者,如果您不想从源代码构建,您可以从[[https://github.com/shouya/rss-funnel/releases][发布页面]]下载预构建的工件。
** 使用方法
要使用 =rss-funnel=,您需要提供一个YAML格式的配置文件。以下是一个示例配置。
#+begin_src yaml endpoints
-
path: /tokio-blog.xml note: Tokio博客源的全文: https://tokio.rs/_next/static/feed.xml filters
- full_text: {}
- simplify_html: {}
-
path: /solidot.xml note: Solidot新闻链接源: https://www.solidot.org/index.rss filters
- full_text: {}
- keep_element: .p_mainnew
- simplify_html: {}
- sanitize
- replace_regex: from: "(?http(s)?://[^< \n]*)" to: '$link'
-
path: /hackernews.xml note: Hacker News的全文: https://news.ycombinator.com/rss filters
- full_text: simplify: true append_mode: true #+end_src
将以上文件保存到 =/path/to/funnel.yaml=,并运行以下命令
#+begin_src rss-funnel -c /path/to/funnel.yaml server #+end_src
您可以指定绑定地址和端口(默认 =127.0.0.1:4080=)。详细使用方法可以在 =--help= 输出中找到。
类似于 =http://127.0.0.1:4080/tokio-blog.xml= 的端点应该提供经过过滤的源。
** 端点
每个配置包含多个端点。每个端点对应一个RSS源。
属性
- =path=(必填):端点的路径。路径应以= /=开始。
- =note=(可选):端点的注释。仅用于显示目的。
- =source=(可选):RSS源文件的URL。
- 如果未指定,必须在请求中指定=?source==查询。这允许对不同的源应用相同的过滤器。
- 如果源指向一个HTML页面,=rss-funnel=将尝试从页面生成一个包含单个文章的RSS源。然后您可以使用=split=过滤器将单个文章拆分为多个文章。有关示例,请参阅[[https://github.com/shouya/rss-funnel/wiki/Cookbook#hacker-news-top-links][食谱:Hacker News Top Links]]。
- =filters=(必填):要应用于源的一系列过滤器。
- =source=的源通过指定顺序的过滤器。您可以将每个过滤器视为对=Feed=的一种转换。
- 每个过滤器都指定为一个具有单例键(过滤器的名称)的YAML对象,其值是过滤器的配置。
- 例如,在过滤器定义:=- keep_element: .p_mainnew=
- 过滤器名称为=keep_element=
- 配置是字符串值=.p_mainnew=。根据过滤器,配置可以有不同的类型。
- 例如,在过滤器定义:=- keep_element: .p_mainnew=
- 返回响应的是最后一个过滤器中的=Feed=对象。
- =client=(可选):用于抓取源的HTTP客户端的配置,例如user_agent。有关详细信息,请参阅[[https://github.com/shouya/rss-funnel/wiki/Client-config][客户端配置]]。
** 过滤器
请参阅[[https://github.com/shouya/rss-funnel/wiki/Filters][过滤器]]以获取所有可用过滤器的文档。
** 食谱
请参阅[[https://github.com/shouya/rss-funnel/wiki/Cookbook][食谱]]以获取使用=rss-funnel=的一些示例。
依赖项
~35–51MB
~1M SLoC