From d2ab8ab3c020bd41e4cc47e5f7e4a0d819fe4583 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 2 Jan 2023 06:35:36 -0700 Subject: [PATCH] feat(core): json feed (#11494) * feat(core): json feed * docs: json feed description * fix: remove extra comma if no elements exist after author * test: json feed test * feat: generate json feed without art-template * test: fix coverage * style: 4 spaces json * docs: fix parameter --- docs/en/parameter.md | 11 ++++----- docs/parameter.md | 13 ++++++----- lib/middleware/template.js | 40 ++++++++++++++++++++++++--------- lib/utils/render.js | 45 +++++++++++++++++++++++++++++++++++++ lib/v2/test/index.js | 40 +++++++++++++++++++++++++++++++++ test/middleware/template.js | 24 +++++++++++++++++--- 6 files changed, 148 insertions(+), 25 deletions(-) diff --git a/docs/en/parameter.md b/docs/en/parameter.md index 3db033920..f67ba56fd 100644 --- a/docs/en/parameter.md +++ b/docs/en/parameter.md @@ -4,17 +4,17 @@ Parameters here are actually URI query and can be linked together with `&` to generate a complex feed. -Parameters here need to be placed after the route path. Some routes may have **custom route parameters** and **parameters here** need to be placed after them. +Parameters here need to be placed after the route path. Some routes may have **custom route parameters** and **parameters here** need to be placed after them. E.g. -https://rsshub.app/twitter/user/durov/readable=1&includeRts=0?brief=100&limit=5 +https://rsshub.app/twitter/user/durov/readable=1&includeRts=0?brief=100&limit=5 -If a **output format** (`.atom`, `.rss`, `.debug.json`) is set, it needs to be placed between the route path (including **custom route parameters**) and **other parameters**. +If a **output format** (`.atom`, `.rss`, `.json`, `.debug.json`) is set, it needs to be placed between the route path (including **custom route parameters**) and **other parameters**. E.g. -https://rsshub.app/twitter/user/durov/readable=1&includeRts=0.atom?brief=100&limit=5 +https://rsshub.app/twitter/user/durov/readable=1&includeRts=0.atom?brief=100&limit=5 ::: @@ -138,13 +138,14 @@ There are more details in the [FAQ](/en/faq.html). ## Output Formats -RSSHub conforms to RSS 2.0 and Atom Standard, simply append `.rss` `.atom` to the end of the feed address to obtain the feed in corresponding format. The default output format is RSS 2.0. +RSSHub conforms to RSS 2.0, Atom and JSON Feed Standard, simply append `.rss`, `.atom` or `.json` to the end of the feed address to obtain the feed in corresponding format. The default output format is RSS 2.0. E.g. - Default (RSS 2.0) - [https://rsshub.app/dribbble/popular](https://rsshub.app/dribbble/popular) - RSS 2.0 - [https://rsshub.app/dribbble/popular.rss](https://rsshub.app/dribbble/popular.rss) - Atom - [https://rsshub.app/dribbble/popular.atom](https://rsshub.app/dribbble/popular.atom) +- JSON Feed - [https://rsshub.app/twitter/user/DIYgod.json](https://rsshub.app/twitter/user/DIYgod.json) - Apply filters or URL query - [https://rsshub.app/dribbble/popular.atom?filterout=Blue|Yellow|Black](https://rsshub.app/dribbble/popular.atom?filterout=Blue|Yellow|Black) ### Debug diff --git a/docs/parameter.md b/docs/parameter.md index 7a04d4afa..9350be2fc 100644 --- a/docs/parameter.md +++ b/docs/parameter.md @@ -4,17 +4,17 @@ 通用参数实际上是 URI 中的 query,可以使用 `&` 连接组合使用,效果叠加。 -通用参数需要置于路由路径的最后。有些路由在路由路径(route path)的最后引入了**自定义参数**,**通用参数**也需要置于它们之后。 +通用参数需要置于路由路径的最后。有些路由在路由路径(route path)的最后引入了**自定义参数**,**通用参数**也需要置于它们之后。 举例: -readable=1\&includeRts=0?brief=100\&limit=5 +readable=1\&includeRts=0?brief=100\&limit=5 -如果设置了**输出格式**(`.atom`, `.rss`, `.debug.json`),则需要置于路由路径(含**自定义参数**)与**其它通用参数**之间。 +如果设置了**输出格式**(`.atom`, `.rss`, `.json`, `.debug.json`),则需要置于路由路径(含**自定义参数**)与**其它通用参数**之间。 举例: -readable=1\&includeRts=0.atom?brief=100\&limit=5 +readable=1\&includeRts=0.atom?brief=100\&limit=5 ::: @@ -131,19 +131,20 @@ Telegram 即时预览模式需要在官网制作页面处理模板,请前往[ - `image_hotlink_template`: 用于处理描述中图片的 URL,绕过防盗链等限制,留空不生效。用法参考 [#2769](https://github.com/DIYgod/RSSHub/issues/2769)。可以使用 [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL#Properties) 的所有属性(加上后缀 `_ue` 则会对其进行 URL 编码),格式为 JS 变量模板。例子:`${protocol}//${host}${pathname}`, `https://i3.wp.com/${host}${pathname}`, `https://images.weserv.nl?url=${href_ue}` - `multimedia_hotlink_template`: 用法同 `image_hotlink_template`,但应用于音频和视频。注意:该服务必须跟随跳转、允许反代音频和视频,且必须在反代时丢弃 `Referer` 请求头。[这里有一个符合要求的易于自行搭建的项目](https://github.com/Rongronggg9/rsstt-img-relay/blob/main/README_zh-CN.md),该项目接受直接拼接 URL,即 `https://example.com/${href}`,其中 `example.com` 应替换为自行搭建的服务的域名 -- `wrap_multimedia_in_iframe`: 将音频和视频包裹在 `