fix(route/harvard): replace selector (#13889)

* Update blog.js

* refactor: migrate to v2

---------
This commit is contained in:
Andvari
2023-11-27 22:46:27 +08:00
committed by GitHub
parent 137dd2860c
commit 92475ea34b
6 changed files with 29 additions and 9 deletions
+1 -1
View File
@@ -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'));
@@ -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;
})
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/health/blog': ['nczitzk'],
};
+13
View File
@@ -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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/health/blog', require('./health/blog'));
};
+1 -1
View File
@@ -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}
<Route author="nczitzk" example="/harvard/health/blog" path="/harvard/health/blog" />