diff --git a/docs/en/new-media.md b/docs/en/new-media.md index fb8c7628c..ddde6afd8 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -434,6 +434,16 @@ Provides a better reading experience (full text articles) over the official one. +## Kuwait Local + +### Latest News + + + +### Categorised News + + + ## Letterboxd ### User diary diff --git a/lib/v2/kuwaitlocal/index.js b/lib/v2/kuwaitlocal/index.js new file mode 100644 index 000000000..0184b2ca7 --- /dev/null +++ b/lib/v2/kuwaitlocal/index.js @@ -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', + }; +}; diff --git a/lib/v2/kuwaitlocal/maintainer.js b/lib/v2/kuwaitlocal/maintainer.js new file mode 100644 index 000000000..385dc7d47 --- /dev/null +++ b/lib/v2/kuwaitlocal/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['TonyRL'], + '/:category?': ['TonyRL'], +}; diff --git a/lib/v2/kuwaitlocal/radar.js b/lib/v2/kuwaitlocal/radar.js new file mode 100644 index 000000000..c60853ca3 --- /dev/null +++ b/lib/v2/kuwaitlocal/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/kuwaitlocal/router.js b/lib/v2/kuwaitlocal/router.js new file mode 100644 index 000000000..9885c36f1 --- /dev/null +++ b/lib/v2/kuwaitlocal/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:category?', require('./index')); +};