From c3f98c3044d1d6e842b25a06a720758451c88c42 Mon Sep 17 00:00:00 2001 From: Theo Date: Sun, 5 Jan 2025 09:22:42 +0800 Subject: [PATCH] chore: update node version to 22 and enhance content extraction --- .vscode/launch.json | 4 ++-- packages/rss-libs/utils/common-utils.js | 10 +++++++++- packages/rss-server/customize/cmu-pavlo/index.js | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3d945a10dcb28e..e0211f4c2dbbbc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "name": "start-rsshub", "skipFiles": ["/**"], "runtimeExecutable": "node", - "runtimeVersion": "20", + "runtimeVersion": "22", "outputCapture": "std", "program": "${workspaceFolder}/packages/rss-server/index.js", "envFile": "${workspaceFolder}/.env", @@ -33,7 +33,7 @@ "name": "start-rsshub (without ssl)", "skipFiles": ["/**"], "runtimeExecutable": "node", - "runtimeVersion": "20", + "runtimeVersion": "22", "outputCapture": "std", "program": "${workspaceFolder}/packages/rss-server/index.js", "envFile": "${workspaceFolder}/.env", diff --git a/packages/rss-libs/utils/common-utils.js b/packages/rss-libs/utils/common-utils.js index 716217ca67edb7..9dc2b645d7291d 100644 --- a/packages/rss-libs/utils/common-utils.js +++ b/packages/rss-libs/utils/common-utils.js @@ -339,7 +339,15 @@ class GenericEndpointBuilder { * @returns {GenericEndpointBuilder} - 当前构建器实例,以便链式调用。 */ withContentExtractor(extractor) { - this.options.contentExtractor = extractor; + if (!this.options.contentExtractor) { + this.options.contentExtractor = extractor; + } else { + const e0 = this.options.contentExtractor; + this.options.contentExtractor = async (...args) => { + return Object.assign({}, await e0(...args), await extractor(...args)) + } + } + return this; } diff --git a/packages/rss-server/customize/cmu-pavlo/index.js b/packages/rss-server/customize/cmu-pavlo/index.js index f34ec8d2a1a90d..68280139e47adf 100644 --- a/packages/rss-server/customize/cmu-pavlo/index.js +++ b/packages/rss-server/customize/cmu-pavlo/index.js @@ -1,10 +1,15 @@ const { GenericEndpointBuilder } = require("rss-libs/utils/common-utils"); +const moment = require("moment"); const endpoint = GenericEndpointBuilder.new() .withEndpointPath("/cmu/pavlo") .withEntryUrl("https://www.cs.cmu.edu/~pavlo/blog/index.html") .withDomAEleLinkExtractor("h4 a") .withAutoContentExtractor() + .withContentExtractor(($) => ({ + // 'Posted on October 03, 2016' + pubDate: moment($(".postdate",).text()?.slice('Posted on '.length), "MMMM DD, YYYY").toISOString(), + })) .build(); module.exports = endpoint;