From 18cf9bcff14aef71beb7a255c797c07ba86fb80a Mon Sep 17 00:00:00 2001 From: Derrick Hwechul Cho Date: Sun, 3 Sep 2023 04:41:30 -0700 Subject: [PATCH] feat(route): add pubDate Transformation/HTML (#13172) * feat(route): add pubDate Transformation/HTML update lib/v2/rsshu:/transform/html.js * feat(route): add pubDate Transformation/JSON update lib/v2/rsshu:/transform/json.js --- lib/v2/rsshub/transform/html.js | 9 +++++++++ lib/v2/rsshub/transform/json.js | 1 + website/docs/routes/other.md | 3 +++ 3 files changed, 13 insertions(+) diff --git a/lib/v2/rsshub/transform/html.js b/lib/v2/rsshub/transform/html.js index c97e62d4a8..c4155789e9 100644 --- a/lib/v2/rsshub/transform/html.js +++ b/lib/v2/rsshub/transform/html.js @@ -55,10 +55,19 @@ module.exports = async (ctx) => { desc = descEle.html(); } + let pubDate; + const pubDateEle = routeParams.get('itemPubDate') ? item.find(routeParams.get('itemPubDate')) : item; + if (routeParams.get('itemPubDateAttr')) { + pubDate = pubDateEle.attr(routeParams.get('itemPubDateAttr')); + } else { + pubDate = pubDateEle.html(); + } + return { title, link, description: desc, + pubDate }; } catch (e) { return null; diff --git a/lib/v2/rsshub/transform/json.js b/lib/v2/rsshub/transform/json.js index 9ca8d40950..b9857eb717 100644 --- a/lib/v2/rsshub/transform/json.js +++ b/lib/v2/rsshub/transform/json.js @@ -45,6 +45,7 @@ module.exports = async (ctx) => { title: jsonGet(item, routeParams.get('itemTitle')), link, description: routeParams.get('itemDesc') ? jsonGet(item, routeParams.get('itemDesc')) : '', + pubDate: routeParams.get('itemPubDate') ? jsonGet(item, routeParams.get('itemPubDate')) : '', }; }); diff --git a/website/docs/routes/other.md b/website/docs/routes/other.md index 5f7ec11fc5..6e7d262ece 100644 --- a/website/docs/routes/other.md +++ b/website/docs/routes/other.md @@ -587,6 +587,8 @@ Specify options (in the format of query string) in parameter `routeParams` param | `itemLinkAttr` | The attributes of `link` element as link | `string` | `href` | | `itemDesc` | The HTML elements as `descrption` in `item` using CSS selector | `string` | `item` element | | `itemDescAttr` | The attributes of `descrption` element as description | `string` | Element html | +| `itemPubDate` | The HTML elements as `pubDate` in `item` using CSS selector | `string` | `item` element | +| `itemPubDateAttr` | The attributes of `pubDate` element as pubDate | `string` | Element html | @@ -616,6 +618,7 @@ Specify options (in the format of query string) in parameter `routeParams` param | `itemTitle` | The JSON Path as `title` in `item` | `string` | None | | `itemLink` | The JSON Path as `link` in `item` | `string` | None | | `itemDesc` | The JSON Path as `description` in `item` | `string` | None | +| `itemPubDate` | The JSON Path as `pubDate` in `item` | `string` | None | :::tip