Skip to content

Commit

Permalink
feat: add Darwin Awards (DIYgod#5262)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoenglinghou authored Jul 29, 2020
1 parent 842d046 commit 580fea5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/en/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](h

<RouteEn author="Gnnng" example="/coronavirus/sg-moh" path="/coronavirus/sg-moh"/>

## Darwin Awards

### Articles

<Route author="zoenglinghou" example="/darwinawards/all" path="/darwinawards/all" />

## dcinside

### board
Expand Down
10 changes: 8 additions & 2 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ pageClass: routes

<Route author="hoilc" example="/clickme/default/category/beauty" path="/clickme/:site/:grouping/:name" :paramsDesc="['站点, `default`为普通站, `r18`为成人站, 其它值默认为普通站','分组方式, `category`为分类, `tag`为标签, 其他值默认为分类','分类名或标签名, 分类名为英文, 可以在分类 URL 中找到']" />

## Darwin Awards

### 文章

<Route author="zoenglinghou" example="/darwinawards/all" path="/darwinawards/all"/>

## dcinside

### board
Expand Down Expand Up @@ -668,8 +674,8 @@ type 为 all 时,category 参数不支持 cost 和 free
### 源仓库更新

<Route author="vhxubo" example="/ku" path="/ku/:name?" :paramsDesc="['默认为 `yuedu`']">
| 阅读 | 异次元 | 海阔 |
| ---- | ----- | ---- |
| 阅读 | 异次元 | 海阔 |
| ----- | -------- | ------ |
| yuedu | yiciyuan | haikuo |

</Route>
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3018,4 +3018,7 @@ router.get('/jlu/oa', require('./routes/universities/jlu/oa'));
// 小宇宙
router.get('/xiaoyuzhou', require('./routes/xiaoyuzhou/pickup'));

// Darwin Awards
router.get('/darwinawards/all', require('./routes/darwinawards/articles'));

module.exports = router;
42 changes: 42 additions & 0 deletions lib/routes/darwinawards/articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'https://darwinawards.com/',
});

const data = response.data;

const $ = cheerio.load(data);
const list = [];
$('div.column.content')
.find('p')
.each(function (index, item) {
if (!$(item).find('a').text().startsWith('20') && $(item).find('a').text() !== '') {
list.push(item);
}
});

let index = 0;

ctx.state.data = {
title: 'Darwin Awards',
link: 'https://darwinawards.com/',
item: list.map(function (item) {
const title = $(item).find('a').text();

const time = new Date();
time.setMinutes(time.getMinutes() - index);
index++;

return {
title: title,
description: $(item).text().replace(title, ''),
link: $(item).find('a').attr('href'),
pubDate: time,
};
}),
};
};

0 comments on commit 580fea5

Please sign in to comment.