Skip to content

Commit

Permalink
feat: add pocket trending (DIYgod#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoilc authored and DIYgod committed Oct 21, 2019
1 parent db9bb6d commit 7838a0f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pageClass: routes

<Route author="fengkx" example="/one" path="/one"/>

## Pocket

### Trending

<Route author="hoilc" example="/pocket/trending" path="/pocket/trending"/>

## SANS Institute

### 最新会议材料
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
26 changes: 26 additions & 0 deletions lib/routes/pocket/trending.js
Original file line number Diff line number Diff line change
@@ -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: `<p>${item.find('.excerpt').text()}</p><img src="${item.find('.item_image').attr('data-thumburl')}" />`,
link: item.find('.item_link').attr('data-saveurl'),
};
}),
};
};

0 comments on commit 7838a0f

Please sign in to comment.