diff --git a/docs/bbs.md b/docs/bbs.md index 11302e5d3..1c6af5e73 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -118,6 +118,12 @@ pageClass: routes +## RF 技术社区 + +### 文章 + + + ## Ruby China > 未登录状态下抓取页面非实时更新 diff --git a/lib/router.js b/lib/router.js index 11f93b1cc..bd0abeb10 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2665,6 +2665,9 @@ router.get('/qingting/channel/:id', require('./routes/qingting/channel')); // 金色财经 router.get('/jinse/lives', require('./routes/jinse/lives')); +// RF技术社区 +router.get('/rf/article', require('./routes/rf/article')); + // University of Massachusetts Amherst router.get('/umass/amherst/ecenews', require('./routes/umass/amherst/ecenews')); router.get('/umass/amherst/csnews', require('./routes/umass/amherst/csnews')); diff --git a/lib/routes/rf/article.js b/lib/routes/rf/article.js new file mode 100644 index 000000000..c2eedeb6b --- /dev/null +++ b/lib/routes/rf/article.js @@ -0,0 +1,40 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://rf.eefocus.com/article/list-all'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + const $ = cheerio.load(response.data); + const list = $('h3.media-heading') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: url.resolve('https://rf.eefocus.com/', a.attr('href')), + }; + }) + .get(); + + ctx.state.data = { + title: 'RF技术社区 - 文章', + link: rootUrl, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + item.pubDate = new Date(content('div.article-subline-desc').eq(0).text().replace('发布时间:', '')).toUTCString(); + item.description = content('div.clearfix.article-content').html(); + return item; + }) + ) + ), + }; +};