diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 3d58ff4cc..c72e3908b 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -175,6 +175,12 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## Harvard Health Publishing + +### Harvard Health Blog + + + ## iDownloadBlog ### iDownloadBlog diff --git a/docs/new-media.md b/docs/new-media.md index c2d5ed478..556d4b9d9 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -288,6 +288,12 @@ Tag +## Harvard Health Publishing + +### Harvard Health Blog + + + ## HKEPC ### HKEPC 電腦領域 diff --git a/lib/router.js b/lib/router.js index 825af6c23..7bb3bafc6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/universities/harvard/health/blog.js b/lib/routes/universities/harvard/health/blog.js new file mode 100644 index 000000000..6f4dd59ab --- /dev/null +++ b/lib/routes/universities/harvard/health/blog.js @@ -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, + }; +};