feat(route): add Harvard Health Blog (#7675)

This commit is contained in:
Ethan Shen 2021-07-17 16:52:01 +08:00 committed by GitHub
parent 7d4b0fce6f
commit f64a6005a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

View File

@ -175,6 +175,12 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
<RouteEn author="loganrockmore" example="/grubstreet" path="/grubstreet" />
## Harvard Health Publishing
### Harvard Health Blog
<RouteEn author="nczitzk" example="/harvard/health/blog" path="/harvard/health/blog" />
## iDownloadBlog
### iDownloadBlog

View File

@ -288,6 +288,12 @@ Tag
<Route author="loganrockmore" example="/grubstreet" path="/grubstreet" />
## Harvard Health Publishing
### Harvard Health Blog
<Route author="nczitzk" example="/harvard/health/blog" path="/harvard/health/blog" />
## HKEPC
### HKEPC 電腦領域

View File

@ -4126,4 +4126,7 @@ router.get('/caus/:category?', require('./routes/caus'));
// 摩点
router.get('/modian/zhongchou/:category?/:sort?/:status?', require('./routes/modian/zhongchou'));
// Harvard
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
module.exports = router;

View File

@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.health.harvard.edu';
const currentUrl = `${rootUrl}/blog`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.text-2xl')
.slice(0, 10)
.map((_, item) => {
item = $(item).parent();
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const date = item.link.substr(item.link.length - 12, 8);
item.description = content('.content-repository-content').html();
item.pubDate = Date.parse(`${date.substr(0, 4)}-${date.substr(4, 2)}-${date.substr(6, 2)}`);
return item;
})
)
);
ctx.state.data = {
title: 'Harvard Health Blog',
link: currentUrl,
item: items,
};
};