feat(route): kuwaitlocal (#10922)
This commit is contained in:
parent
381171e442
commit
cb996d3de7
|
|
@ -434,6 +434,16 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## Kuwait Local
|
||||
|
||||
### Latest News
|
||||
|
||||
<RouteEn author="TonyRL" example="/kuwaitlocal" path="/kuwaitlocal" radar="1" rssbud="1"/>
|
||||
|
||||
### Categorised News
|
||||
|
||||
<RouteEn author="TonyRL" example="/kuwaitlocal/article" path="/kuwaitlocal/:category?" :paramsDesc="['Category name, can be found in URL, `latest` by default']" radar="1" rssbud="1"/>
|
||||
|
||||
## Letterboxd
|
||||
|
||||
### User diary
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const baseUrl = 'https://kuwaitlocal.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { category = 'latest' } = ctx.params;
|
||||
const url = `${baseUrl}/news/${category === 'latest' ? category : `categories/${category}`}`;
|
||||
|
||||
const { data: response } = await got(url);
|
||||
const $ = cheerio.load(response);
|
||||
const list = $('.news_list a')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: baseUrl + item.attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
item.pubDate = parseDate($('.date_icon').next().text());
|
||||
$('[id^=div-gpt-ad], .pad_10_0, .hide_desktop').remove();
|
||||
item.description = $('.mob_pad_view').html();
|
||||
item.category = $('.news_tags a')
|
||||
.toArray()
|
||||
.map((item) => $(item).text());
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('head title').text().trim(),
|
||||
description: $('head meta[name="description"]').attr('content').trim(),
|
||||
link: url,
|
||||
item: items,
|
||||
language: 'en',
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
'/': ['TonyRL'],
|
||||
'/:category?': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
module.exports = {
|
||||
'kuwaitlocal.com': {
|
||||
_name: 'Kuwait Local',
|
||||
'.': [
|
||||
{
|
||||
title: 'Latest News',
|
||||
docs: 'https://docs.rsshub.app/en/new-media.html#kuwait-local',
|
||||
source: ['/news/latest', '/news', '/'],
|
||||
target: '/kuwaitlocal',
|
||||
},
|
||||
{
|
||||
title: 'Categorised News',
|
||||
docs: 'https://docs.rsshub.app/en/new-media.html#kuwait-local',
|
||||
source: ['/news/categories/:category'],
|
||||
target: '/kuwaitlocal/:category',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/:category?', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue