From 5f98e1cdc17c403f086adcc9e9c4631e68d2c65a Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 15 Oct 2020 08:57:40 +0800 Subject: [PATCH] feat: add route of 'front-end-rss.now.sh' --- docs/programming.md | 5 +++++ lib/router.js | 3 +++ lib/routes/frontend/index.js | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 lib/routes/frontend/index.js 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, + }; +};