feat(route): kuwaitlocal (#10922)

This commit is contained in:
Tony
2022-09-28 05:04:28 +08:00
committed by GitHub
parent 381171e442
commit cb996d3de7
5 changed files with 83 additions and 0 deletions
+47
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',
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/': ['TonyRL'],
'/:category?': ['TonyRL'],
};
+19
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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./index'));
};