From 92475ea34b1bdc858cea3cb0d8375bbc6016b99b Mon Sep 17 00:00:00 2001
From: Andvari <31068367+dzx-dzx@users.noreply.github.com>
Date: Mon, 27 Nov 2023 22:46:27 +0800
Subject: [PATCH 1/2] fix(route/harvard): replace selector (#13889)
* Update blog.js
* refactor: migrate to v2
---------
---
lib/router.js | 2 +-
.../universities => v2}/harvard/health/blog.js | 15 ++++++++-------
lib/v2/harvard/maintainer.js | 3 +++
lib/v2/harvard/radar.js | 13 +++++++++++++
lib/v2/harvard/router.js | 3 +++
website/docs/routes/new-media.mdx | 2 +-
6 files changed, 29 insertions(+), 9 deletions(-)
rename lib/{routes/universities => v2}/harvard/health/blog.js (72%)
create mode 100644 lib/v2/harvard/maintainer.js
create mode 100644 lib/v2/harvard/radar.js
create mode 100644 lib/v2/harvard/router.js
diff --git a/lib/router.js b/lib/router.js
index aa8fa4323c3096..58e8410d284d37 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2594,7 +2594,7 @@ router.get('/cbndata/information/:category?', lazyloadRouteHandler('./routes/cbn
router.get('/tanchinese/:category?', lazyloadRouteHandler('./routes/tanchinese'));
// Harvard
-router.get('/harvard/health/blog', lazyloadRouteHandler('./routes/universities/harvard/health/blog'));
+// router.get('/harvard/health/blog', lazyloadRouteHandler('./routes/universities/harvard/health/blog'));
// yuzu emulator
router.get('/yuzu-emu/entry', lazyloadRouteHandler('./routes/yuzu-emu/entry'));
diff --git a/lib/routes/universities/harvard/health/blog.js b/lib/v2/harvard/health/blog.js
similarity index 72%
rename from lib/routes/universities/harvard/health/blog.js
rename to lib/v2/harvard/health/blog.js
index 6aea504581774a..8de8d9e6882966 100644
--- a/lib/routes/universities/harvard/health/blog.js
+++ b/lib/v2/harvard/health/blog.js
@@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://www.health.harvard.edu';
@@ -12,17 +13,16 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
- const list = $('.text-2xl')
- .slice(0, 10)
- .map((_, item) => {
+ const list = $('.lg\\:text-2xl')
+ .toArray()
+ .map((item) => {
item = $(item).parent();
return {
title: item.text(),
link: item.attr('href'),
};
- })
- .get();
+ });
const items = await Promise.all(
list.map((item) =>
@@ -33,10 +33,11 @@ module.exports = async (ctx) => {
});
const content = cheerio.load(detailResponse.data);
- const date = item.link.substr(item.link.length - 12, 8);
+ const ldJson = JSON.parse(content('script[type="application/ld+json"]').text())['@graph'].find((i) => i['@type'] === 'Article');
item.description = content('.content-repository-content').html();
- item.pubDate = Date.parse(`${date.substr(0, 4)}-${date.substr(4, 2)}-${date.substr(6, 2)}`);
+ item.pubDate = parseDate(ldJson.datePublished);
+ item.author = ldJson.author.name;
return item;
})
diff --git a/lib/v2/harvard/maintainer.js b/lib/v2/harvard/maintainer.js
new file mode 100644
index 00000000000000..bd44d1faa3e65f
--- /dev/null
+++ b/lib/v2/harvard/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/health/blog': ['nczitzk'],
+};
diff --git a/lib/v2/harvard/radar.js b/lib/v2/harvard/radar.js
new file mode 100644
index 00000000000000..f36cbf6aef011a
--- /dev/null
+++ b/lib/v2/harvard/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'harvard.edu': {
+ _name: 'Harvard University',
+ 'www.health': [
+ {
+ title: 'Health Blog',
+ docs: 'https://docs.rsshub.app/routes/new-media#harvard-health-publishing',
+ source: ['/blog'],
+ target: '/harvard/health/blog',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/harvard/router.js b/lib/v2/harvard/router.js
new file mode 100644
index 00000000000000..02dd70750abe9c
--- /dev/null
+++ b/lib/v2/harvard/router.js
@@ -0,0 +1,3 @@
+module.exports = (router) => {
+ router.get('/health/blog', require('./health/blog'));
+};
diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx
index 376a70ef59962a..f1d52386bf9522 100644
--- a/website/docs/routes/new-media.mdx
+++ b/website/docs/routes/new-media.mdx
@@ -909,7 +909,7 @@ Click here to view [All Topics](https://hbr.org/topics)
## Harvard Health Publishing {#harvard-health-publishing}
-### Harvard Health Blog {#harvard-health-publishing-harvard-health-blog}
+### Health Blog {#harvard-health-publishing-harvard-health-blog}
From 08c88c2c718f0a465aa07fe34295a67109fa4e6a Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Mon, 27 Nov 2023 14:48:16 +0000
Subject: [PATCH 2/2] style: auto format
---
website/docs/routes/new-media.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx
index f1d52386bf9522..ca8c99a77a16a9 100644
--- a/website/docs/routes/new-media.mdx
+++ b/website/docs/routes/new-media.mdx
@@ -909,7 +909,7 @@ Click here to view [All Topics](https://hbr.org/topics)
## Harvard Health Publishing {#harvard-health-publishing}
-### Health Blog {#harvard-health-publishing-harvard-health-blog}
+### Health Blog {#harvard-health-publishing-health-blog}