diff --git a/docs/en/new-media.md b/docs/en/new-media.md index a9aeac7d7d..fdcc845e5a 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -372,6 +372,12 @@ Compared to the official one, this feed: +## RSS3 + +### Blog + + + ## Research Gate ### Publications diff --git a/docs/new-media.md b/docs/new-media.md index 0161ab4882..c7800bfadd 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -713,6 +713,12 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## RSS3 + +### Blog + + + ## Research Gate ### Publications diff --git a/lib/router.js b/lib/router.js index a390cbf924..804b09c362 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4218,4 +4218,7 @@ router.get('/researchgate/publications/:id', require('./routes/researchgate/publ // QuestMobile router.get('/questmobile/report/:category?/:label?', require('./routes/questmobile/report')); +// RSS3 +router.get('/rss3/blog', require('./routes/rss3/blog')); + module.exports = router; diff --git a/lib/routes/rss3/blog.js b/lib/routes/rss3/blog.js new file mode 100644 index 0000000000..efc789a978 --- /dev/null +++ b/lib/routes/rss3/blog.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://blog.rss3.io'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('h1 a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${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); + + item.description = content('.post-content').html(); + item.pubDate = Date.parse(content('small time').attr('datetime')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Blog - RSS3', + link: rootUrl, + item: items, + }; +};