feat(route): add NL Times (#8127)
* feat(route): add NL Times * refactor: migrate to v2 * fix: tryGet cache Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
7445cee887
commit
8537de593a
|
|
@ -483,6 +483,18 @@ This route provides a flexible plan with full text content to subscribe specific
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## NL Times
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="Hivol" example="/nltimes/news/top-stories" path="/nltimes/news/:category?" :paramsDesc="['category']" >
|
||||
|
||||
| Top Stories (default) | Health | Crime | Politics | Business | Tech | Culture | Sports | Weird | 1-1-2 |
|
||||
| --------------------- | ------ | ----- | -------- | -------- | ---- | ------- | ------ | ----- | ----- |
|
||||
| top-stories | health | crime | politics | business | tech | culture | sports | weird | 1-1-2 |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Oak Ridge National Laboratory
|
||||
|
||||
### News
|
||||
|
|
|
|||
|
|
@ -837,6 +837,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
|||
|
||||
</Route>
|
||||
|
||||
## NL Times
|
||||
|
||||
### News
|
||||
|
||||
<Route author="Hivol" example="/nltimes/news/top-stories" path="/nltimes/news/:category?" :paramsDesc="['分类名']" >
|
||||
|
||||
| Top Stories (默认) | Health | Crime | Politics | Business | Tech | Culture | Sports | Weird | 1-1-2 |
|
||||
| ---------------- | ------ | ----- | -------- | -------- | ---- | ------- | ------ | ----- | ----- |
|
||||
| top-stories | health | crime | politics | business | tech | culture | sports | weird | 1-1-2 |
|
||||
|
||||
</Route>
|
||||
|
||||
## Odaily 星球日报
|
||||
|
||||
### 快讯
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news/:category?': ['Hivol'],
|
||||
};
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const map = new Map([
|
||||
['top-stories', { title: 'NL Times -- Top Stories', suffix: '/top-stories' }],
|
||||
['health', { title: 'NL Times -- Health', suffix: '/categories/health' }],
|
||||
['crime', { title: 'NL Times -- Crime', suffix: '/categories/crime' }],
|
||||
['politics', { title: 'NL Times -- Politics', suffix: '/categories/politics' }],
|
||||
['business', { title: 'NL Times -- Business', suffix: '/categories/business' }],
|
||||
['tech', { title: 'NL Times -- Tech', suffix: '/categories/tech' }],
|
||||
['culture', { title: 'NL Times -- Culture', suffix: '/categories/culture' }],
|
||||
['sports', { title: 'NL Times -- Sports', suffix: '/categories/sports' }],
|
||||
['weird', { title: 'NL Times -- Weird', suffix: '/categories/weird' }],
|
||||
['1-1-2', { title: 'NL Times -- 1-1-2', suffix: '/categories/1-1-2' }],
|
||||
]);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'top-stories';
|
||||
const suffix = map.get(category).suffix;
|
||||
|
||||
const rootUrl = 'https://www.nltimes.nl';
|
||||
const apiUrl = rootUrl + suffix;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.news-card')
|
||||
.slice(0, 10)
|
||||
.map((_, elem) => {
|
||||
const item = {
|
||||
link: $(elem).children('.news-card__title').first().children('a').first().attr('href'),
|
||||
title: $(elem).children('.news-card__title').first().children('a').first().text(),
|
||||
date: $(elem).children('.news-card__date').first().text(),
|
||||
category: $(elem)
|
||||
.children('.news-card__categories')
|
||||
.first()
|
||||
.children('a')
|
||||
.map((_, elem) => $(elem).text())
|
||||
.get(),
|
||||
};
|
||||
return item;
|
||||
})
|
||||
.get();
|
||||
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
return $('.news-article--body').html();
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) => {
|
||||
const title = item.title;
|
||||
const date = timezone(parseDate(item.date, 'DD MMMM YYYY - HH:mm'), +1); // Central European Time
|
||||
const link = rootUrl + item.link;
|
||||
const category = item.category;
|
||||
|
||||
return ctx.cache.tryGet(link, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const description = ProcessFeed(response.data);
|
||||
return {
|
||||
title,
|
||||
category,
|
||||
description,
|
||||
pubDate: date,
|
||||
link,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: map.get(category).title,
|
||||
language: 'en',
|
||||
link: apiUrl,
|
||||
description: map.get(category).title,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
module.exports = {
|
||||
'nltimes.nl': {
|
||||
_name: 'NL Times',
|
||||
'.': [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#nl-times',
|
||||
source: '/categories/:category',
|
||||
target: '/nltimes/news/:category',
|
||||
},
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#nl-times',
|
||||
source: '/top-stories',
|
||||
target: '/nltimes/news/top-stories',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/news/:category?', require('./news'));
|
||||
};
|
||||
Loading…
Reference in New Issue