fix(route): Darwin Awards (#10136)

* fix(route): Darwin Awards

* fix typo
This commit is contained in:
Ethan Shen 2022-07-05 21:05:33 +08:00 committed by GitHub
parent 56e998d0a9
commit 1c8812b074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 47 deletions

View File

@ -59,9 +59,9 @@ Official Website: <https://news.yahoo.co.jp/pages/article/20200207>
## Darwin Awards
### Articles
### Award Winners
<RouteEn author="zoenglinghou" example="/darwinawards/all" path="/darwinawards/all" />
<RouteEn author="zoenglinghou nciztzk" example="/darwinawards" path="/darwinawards" />
## dcinside

View File

@ -99,9 +99,9 @@ pageClass: routes
## Darwin Awards
### 文章
### Award Winners
<Route author="zoenglinghou" example="/darwinawards/all" path="/darwinawards/all"/>
<Route author="zoenglinghou nciztzk" example="/darwinawards" path="/darwinawards" />
## dcinside

View File

@ -3034,7 +3034,7 @@ router.get('/jlu/oa', lazyloadRouteHandler('./routes/universities/jlu/oa'));
router.get('/hfut/tzgg', lazyloadRouteHandler('./routes/universities/hfut/tzgg'));
// Darwin Awards
router.get('/darwinawards/all', lazyloadRouteHandler('./routes/darwinawards/articles'));
// router.get('/darwinawards/all', lazyloadRouteHandler('./routes/darwinawards/articles'));
// 四川职业技术学院
router.get('/scvtc/xygg', lazyloadRouteHandler('./routes/universities/scvtc/xygg'));

View File

@ -1,42 +0,0 @@
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((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((item) => {
const title = $(item).find('a').text();
const time = new Date();
time.setMinutes(time.getMinutes() - index);
index++;
return {
title,
description: $(item).text().replace(title, ''),
link: $(item).find('a').attr('href'),
pubDate: time,
};
}),
};
};

View File

@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://darwinawards.com';
const currentUrl = `${rootUrl}/darwin/`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('.cameo').remove();
$('.topvote_title_desc, .topvote_title_minimal, .topvote_minimal').each(function () {
$(this).find('a').first().remove();
});
let items = $('#article_index a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('h2, nav, footer, table, form').remove();
item.description = content('article').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/all': ['zoenglinghou', 'nczitzk'],
'/': ['nczitzk'],
};

View File

@ -0,0 +1,13 @@
module.exports = {
'darwinawards.com': {
_name: 'Darwin Awards',
'.': [
{
title: 'Award Winners',
docs: 'https://docs.rsshub.app/other.html#darwin-awards-award-winners',
source: ['/darwin', '/'],
target: '/darwinawards',
},
],
},
};

View File

@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/all', require('./index'));
router.get('/', require('./index'));
};