From 7838a0f238cadfef78efea9f4d619bbfe100f229 Mon Sep 17 00:00:00 2001 From: hoilc Date: Mon, 21 Oct 2019 12:05:47 +0800 Subject: [PATCH] feat: add pocket trending (#3297) --- docs/other.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/pocket/trending.js | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lib/routes/pocket/trending.js diff --git a/docs/other.md b/docs/other.md index 81be2a622f..4c66281019 100644 --- a/docs/other.md +++ b/docs/other.md @@ -71,6 +71,12 @@ pageClass: routes +## Pocket + +### Trending + + + ## SANS Institute ### 最新会议材料 diff --git a/lib/router.js b/lib/router.js index d6965d7b47..75f25567c3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1861,4 +1861,7 @@ router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous // kaggle router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion')); +// Pocket +router.get('/pocket/trending', require('./routes/pocket/trending')); + module.exports = router; diff --git a/lib/routes/pocket/trending.js b/lib/routes/pocket/trending.js new file mode 100644 index 0000000000..83736c9eb8 --- /dev/null +++ b/lib/routes/pocket/trending.js @@ -0,0 +1,26 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'https://getpocket.com/explore/trending'; + + const response = await got.get(url); + const $ = cheerio.load(response.data); + + const list = $('.item').toArray(); + + ctx.state.data = { + title: 'Trending on Pocket', + description: 'Top Articles and Videos about Trending on Pocket', + link: url, + item: list.map((item) => { + item = $(item); + return { + title: item.find('.title').text(), + author: item.find('.domain > a').text(), + description: `

${item.find('.excerpt').text()}

`, + link: item.find('.item_link').attr('data-saveurl'), + }; + }), + }; +};