From 5f98e1cdc17c403f086adcc9e9c4631e68d2c65a Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 15 Oct 2020 08:57:40 +0800 Subject: [PATCH 1/5] 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 d0490d1664..17894c8fa0 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 fad8c2a4b8..f12144876f 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 0000000000..144d2d4e87 --- /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, + }; +}; From 88b649736e664d85e67d9dc93d717a3c4477ac0d Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 15 Oct 2020 18:13:06 +0800 Subject: [PATCH 2/5] fix: add author for each item --- lib/routes/frontend/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/routes/frontend/index.js b/lib/routes/frontend/index.js index 144d2d4e87..b34aed107e 100644 --- a/lib/routes/frontend/index.js +++ b/lib/routes/frontend/index.js @@ -12,6 +12,7 @@ module.exports = async (ctx) => { link: item.link, pubDate: item.date, title: item.title, + author: category.author })), ], [] From 9f784fad1a03f257a6bd51602262b5940a80d026 Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 15 Oct 2020 18:18:27 +0800 Subject: [PATCH 3/5] fix: wrong key property --- lib/routes/frontend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/frontend/index.js b/lib/routes/frontend/index.js index b34aed107e..44e943d7c6 100644 --- a/lib/routes/frontend/index.js +++ b/lib/routes/frontend/index.js @@ -12,7 +12,7 @@ module.exports = async (ctx) => { link: item.link, pubDate: item.date, title: item.title, - author: category.author + author: category.title })), ], [] From ba7d7c4756418579458ab816db56194d1a4b926a Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Thu, 15 Oct 2020 18:57:00 +0800 Subject: [PATCH 4/5] fix: set category title as description --- lib/routes/frontend/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/routes/frontend/index.js b/lib/routes/frontend/index.js index 44e943d7c6..719049ed26 100644 --- a/lib/routes/frontend/index.js +++ b/lib/routes/frontend/index.js @@ -12,7 +12,8 @@ module.exports = async (ctx) => { link: item.link, pubDate: item.date, title: item.title, - author: category.title + author: category.title, + description: category.title })), ], [] From f164f8d27bd37d72c050ebd15ce6d63da907945c Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Mon, 19 Oct 2020 09:56:05 +0800 Subject: [PATCH 5/5] change route name --- lib/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/router.js b/lib/router.js index f12144876f..5c521c2fd7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2059,7 +2059,7 @@ 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('/front-end-rss', require('./routes/frontend/index')); // 国家应急广播 router.get('/cneb/yjxx', require('./routes/cneb/yjxx'));