diff --git a/docs/programming.md b/docs/programming.md index d0490d166..17894c8fa 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -660,6 +660,11 @@ GitHub 官方也提供了一些 RSS: +## 前端技术文章 + + + + ## 前端艺术家 && 飞冰早报 ### 列表 diff --git a/lib/router.js b/lib/router.js index fad8c2a4b..f12144876 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2058,6 +2058,9 @@ router.get('/szse/rule', require('./routes/szse/rule')); // 前端艺术家每日整理&&飞冰早报 router.get('/jskou/:type?', require('./routes/jskou/index')); +// 前端 +router.get('/frontend', require('./routes/frontend/index')); + // 国家应急广播 router.get('/cneb/yjxx', require('./routes/cneb/yjxx')); router.get('/cneb/guoneinews', require('./routes/cneb/guoneinews')); diff --git a/lib/routes/frontend/index.js b/lib/routes/frontend/index.js new file mode 100644 index 000000000..144d2d4e8 --- /dev/null +++ b/lib/routes/frontend/index.js @@ -0,0 +1,25 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got.get(`https://front-end-rss.now.sh/`); + const $ = cheerio.load(response.data); + const fn = Function($($('script')[1]).html() + 'return Array.isArray(LINKS_DATA) ? LINKS_DATA : []'); + const items = fn().reduce( + (acc, category) => [ + ...acc, + ...category.items.map((item) => ({ + link: item.link, + pubDate: item.date, + title: item.title, + })), + ], + [] + ); + + ctx.state.data = { + title: '前端技术文章', + link: 'https://front-end-rss.now.sh/', + item: items, + }; +};