feat: add Nobel Prize lists (#5716)
Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
parent
6b7f357e88
commit
10b975d73d
|
|
@ -117,6 +117,18 @@ Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](h
|
|||
|
||||
<Route author="sbilly" example="/mitre/publications" path="/mitre/publications" />
|
||||
|
||||
## Nobel Prize
|
||||
|
||||
### List
|
||||
|
||||
<RouteEn author="nczitzk" example="/nobelprize" path="/nobelprize/:caty" :paramsDesc="['Category, see below, all by default']">
|
||||
|
||||
| Physics | Chemistry | Physiology or Medicine | Literature | Peace | Economic Science |
|
||||
| ------- | --------- | ---------------------- | ---------- | ----- | ----------------- |
|
||||
| physics | chemistry | physiology-or-medicine | literature | peace | economic-sciences |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Parcel Tracking
|
||||
|
||||
### Hermes UK
|
||||
|
|
|
|||
|
|
@ -521,6 +521,18 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
<Route author="cc798461" example="/moxingnet" path="/moxingnet"/>
|
||||
|
||||
## 诺贝尔奖
|
||||
|
||||
### 获奖名单
|
||||
|
||||
<Route author="nczitzk" example="/nobelprize" path="/nobelprize/:caty" :paramsDesc="['类别,见下表,默认为全部']">
|
||||
|
||||
| 物理学 | 化学 | 生理学或医学 | 文学 | 和平 | 经济学 |
|
||||
| ------- | --------- | ---------------------- | ---------- | ----- | ----------------- |
|
||||
| physics | chemistry | physiology-or-medicine | literature | peace | economic-sciences |
|
||||
|
||||
</Route>
|
||||
|
||||
## 且听风吟福利
|
||||
|
||||
### 分类
|
||||
|
|
|
|||
|
|
@ -3240,6 +3240,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));
|
|||
// CGTN
|
||||
router.get('/cgtn/top', require('./routes/cgtn/top'));
|
||||
|
||||
// Nobel Prize
|
||||
router.get('/nobelprize/:caty?', require('./routes/nobelprize/index'));
|
||||
|
||||
// 中華民國國防部
|
||||
router.get('/gov/taiwan/mnd', require('./routes/gov/taiwan/mnd'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const config = {
|
||||
physics: {
|
||||
link: 'all-nobel-prizes-in-physics',
|
||||
title: 'Physics',
|
||||
},
|
||||
chemistry: {
|
||||
link: 'all-nobel-prizes-in-chemistry',
|
||||
title: 'Chemistry',
|
||||
},
|
||||
'physiology-or-medicine': {
|
||||
link: 'all-nobel-laureates-in-physiology-or-medicine',
|
||||
title: 'Physiology or Medicine',
|
||||
},
|
||||
literature: {
|
||||
link: 'all-nobel-prizes-in-literature',
|
||||
title: 'Literature',
|
||||
},
|
||||
peace: {
|
||||
link: 'all-nobel-peace-prizes',
|
||||
title: 'Peace',
|
||||
},
|
||||
'economic-sciences': {
|
||||
link: 'all-prizes-in-economic-sciences',
|
||||
title: 'Economic Science',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let rootUrl = 'https://www.nobelprize.org/prizes/lists/all-nobel-prizes/';
|
||||
|
||||
const cfg = config[ctx.params.caty];
|
||||
if (cfg) {
|
||||
rootUrl = `https://www.nobelprize.org/prizes/lists/${cfg.link}/`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const items = $('div.by_year h3')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
if (item.text().length === 4) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
|
||||
const a = item.find('a');
|
||||
|
||||
let description = '';
|
||||
|
||||
item.nextAll().each(function () {
|
||||
if ($(this).get(0).tagName === 'p') {
|
||||
description += `<p>${$(this).html()}</p>`;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: new Date(`${a.text().match(/([0-9]{4})/)[1]}-01-01 00:00:00 GMT+0`).toUTCString(),
|
||||
description,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').eq(0).text(),
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue