feat(route): kuwaitlocal (#10922)

This commit is contained in:
Tony 2022-09-27 16:04:28 -05:00 committed by GitHub
parent 381171e442
commit cb996d3de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 0 deletions

View File

@ -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

View File

@ -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',
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/': ['TonyRL'],
'/:category?': ['TonyRL'],
};

View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./index'));
};