feat(route): add Kantar Worldpanel News Centre (#13199)
* feat(route): add Kantar Worldpanel News Centre * fix regular expression for hostnames * fix regular expression for hostnames * fix typo * fix: redirection to kantar.com * docs: fix table * docs: fix header level ---------
This commit is contained in:
parent
851f4267d1
commit
e86ad59f95
|
|
@ -0,0 +1,96 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { region = 'cn-en', category = 'news' } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const rootUrl = 'https://www.kantarworldpanel.com/';
|
||||
const currentUrl = new URL(`${region}/${category}`, rootUrl).href;
|
||||
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
let items = $('ul.slide, #newssource')
|
||||
.find('li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a');
|
||||
const image = item.find('img');
|
||||
|
||||
const title = item.find('h3.mediumFont').text().trim();
|
||||
|
||||
let link = a.prop('href');
|
||||
link = link === '#' ? currentUrl : link;
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
description: item.find('p.gowhite').text(),
|
||||
image: image.prop('src')
|
||||
? {
|
||||
src: image.prop('src'),
|
||||
alt: image.prop('alt'),
|
||||
}
|
||||
: undefined,
|
||||
}),
|
||||
guid: link.startsWith(rootUrl) ? `${link}#${title}` : link,
|
||||
pubDate: parseDate(item.find('p.medGrey').text(), 'DD/MM/YYYY'),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
// The URL similar to the example below is the file download URL.
|
||||
// eg. https://www.kantarworldpanel.com/dwl.php?sn=publications&id=1632.
|
||||
if (item.link === currentUrl || !item.link.startsWith(rootUrl)) {
|
||||
return item;
|
||||
} else if (/dwl\.php/.test(item.link)) {
|
||||
item.enclosure_url = item.link;
|
||||
item.enclosure_type = 'application/pdf';
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
const detailResponse = await got(item.link);
|
||||
|
||||
if (!detailResponse.url.startsWith(rootUrl)) {
|
||||
return item;
|
||||
}
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('h1.newshead').text();
|
||||
item.description = content('div.center-content div.left-layout-col').html();
|
||||
item.category = content('meta[name="keywords"]').prop('content')?.split(/,\s?/) ?? [];
|
||||
item.pubDate = parseDate(content('p.newsdateshare').text(), 'DD/MM/YYYY');
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const icon = new URL('favicon.ico', rootUrl).href;
|
||||
|
||||
ctx.state.data = {
|
||||
item: items,
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
description: $('meta[name="description"]').prop('content'),
|
||||
language: $('html').prop('lang'),
|
||||
image: $('#logoprint img').prop('src'),
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: $('meta[name="keywords"]').prop('content'),
|
||||
allowEmpty: true,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:region/:category?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
module.exports = {
|
||||
'kantarworldpanel.com': {
|
||||
_name: 'Kantar Worldpanel',
|
||||
'.': [
|
||||
{
|
||||
title: 'News Centre China Eng - News',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn-en/news'],
|
||||
target: '/kantarworldpanel/cn-en/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China Eng - Retail Snapshot',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn-en/publications'],
|
||||
target: '/kantarworldpanel/cn-en/publications',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China Eng - Publications',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn-en/publications/Reports'],
|
||||
target: '/kantarworldpanel/cn-en/publications/Reports',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China Eng - In the media',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn-en/In-the-media'],
|
||||
target: '/kantarworldpanel/cn-en/In-the-media',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China 中文 - 新闻发布',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn/news'],
|
||||
target: '/kantarworldpanel/cn/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China 中文 - 零售市场快报',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn/publications'],
|
||||
target: '/kantarworldpanel/cn/publications',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China 中文 - 市场报告',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn/publications/China-Insights'],
|
||||
target: '/kantarworldpanel/cn/publications/China-Insights',
|
||||
},
|
||||
{
|
||||
title: 'News Centre China 中文 - 媒体报道',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/cn/press-releases'],
|
||||
target: '/kantarworldpanel/cn/press-releases',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - News',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News'],
|
||||
target: '/kantarworldpanel/id/News',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - Kantar Scoop',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News/Kantar-Worldpanel-Series'],
|
||||
target: '/kantarworldpanel/id/News/Kantar-Worldpanel-Series',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - Video Series',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News/video-series'],
|
||||
target: '/kantarworldpanel/id/News/video-series',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - Podcast',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News/podcast'],
|
||||
target: '/kantarworldpanel/id/News/podcast',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - Ready, Steady, Shop!',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News/asia-shopper-series'],
|
||||
target: '/kantarworldpanel/id/News/asia-shopper-series',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Indonesia - Asia Pulse',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/id/News/Asia-Pulse'],
|
||||
target: '/kantarworldpanel/id/News/Asia-Pulse',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Korea - News',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/kr/news'],
|
||||
target: '/kantarworldpanel/kr/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Korea - Insight Reports',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/kr/publications'],
|
||||
target: '/kantarworldpanel/kr/publications',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Korea - In the Media',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/kr/press-releases'],
|
||||
target: '/kantarworldpanel/kr/press-releases',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Malaysia - News',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/my/news'],
|
||||
target: '/kantarworldpanel/my/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Philippines - Latest Insights',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/ph/Latest-Insights'],
|
||||
target: '/kantarworldpanel/ph/Latest-Insights',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Philippines - In the Media',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/ph/In-the-Media'],
|
||||
target: '/kantarworldpanel/ph/In-the-Media',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Philippines - Events',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/ph/events'],
|
||||
target: '/kantarworldpanel/ph/events',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Taiwan - 聚焦台灣',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/ph/news/spotlight-on-taiwan'],
|
||||
target: '/kantarworldpanel/tw/news/spotlight-on-taiwan',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Taiwan - WOW SPOT',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/tw/news/wowspot'],
|
||||
target: '/kantarworldpanel/tw/news/wowspot',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Taiwan - 市場報告',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/tw/publications'],
|
||||
target: '/kantarworldpanel/tw/publications',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Taiwan - 媒體報導',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/tw/press-releases'],
|
||||
target: '/kantarworldpanel/tw/press-releases',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Taiwan - 活動',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/tw/events'],
|
||||
target: '/kantarworldpanel/tw/events',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Thailand - News',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/th/news'],
|
||||
target: '/kantarworldpanel/th/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Vietnam - Insights',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/vn/news'],
|
||||
target: '/kantarworldpanel/vn/news',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Vietnam - FMCG Monitor',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/vn/news/FMCG-Monitor'],
|
||||
target: '/kantarworldpanel/vn/news/FMCG-Monitor',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Vietnam - Ready, Steady, Shop!',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/vn/news/ready-steady-shop'],
|
||||
target: '/kantarworldpanel/vn/news/ready-steady-shop',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Vietnam - Asia Pulse',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/vn/news/asia-pulse'],
|
||||
target: '/kantarworldpanel/vn/news/asia-pulse',
|
||||
},
|
||||
{
|
||||
title: 'News Centre Vietnam - IN THE MEDIA',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
|
||||
source: ['/vn/In-the-media'],
|
||||
target: '/kantarworldpanel/vn/In-the-media',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/:region?/:category*', require('./'));
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{{ if description }}
|
||||
{{@ description }}
|
||||
{{ /if }}
|
||||
|
||||
{{ if image }}
|
||||
<figure>
|
||||
<img src="{{ image }}">
|
||||
</figure>
|
||||
{{ /if }}
|
||||
|
|
@ -959,6 +959,85 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
|
||||
</Route>
|
||||
|
||||
## Kantar Worldpanel {#kantar-worldpanel}
|
||||
|
||||
### News Centre {#kantar-worldpanel-news-centre}
|
||||
|
||||
<Route author="nczitzk" example="/kantarworldpanel/cn-en/news" path="/kantarworldpanel/:region/:category?" paramsDesc={['Region id, see below, Chinese Mainland English by default', 'Category, can be found in URL, News by default']} radar="1" rssbud="1">
|
||||
|
||||
| Region | id |
|
||||
| ----------- | ----- |
|
||||
| China Eng | cn-en |
|
||||
| China 中文 | cn |
|
||||
| Indonesia | id |
|
||||
| Korea | kr |
|
||||
| Malaysia | my |
|
||||
| Philippines | ph |
|
||||
| Taiwan | tw |
|
||||
| Thailand | th |
|
||||
| Vietnam | vn |
|
||||
|
||||
<details>
|
||||
<summary>More categories</summary>
|
||||
|
||||
#### China Eng {#kantar-worldpanel-news-centre-china-eng}
|
||||
|
||||
| News | Retail Snapshot | Publications | In the media |
|
||||
| ---- | --------------- | -------------------- | ------------ |
|
||||
| news | publications | publications/Reports | In-the-media |
|
||||
|
||||
#### China 中文 {#kantar-worldpanel-news-centre-china-zhong-wen}
|
||||
|
||||
| 新闻发布 | 零售市场快报 | 市场报告 | 媒体报道 |
|
||||
| -------- | ------------ | --------------------------- | -------------- |
|
||||
| news | publications | publications/China-Insights | press-releases |
|
||||
|
||||
#### Indonesia {#kantar-worldpanel-news-centre-indonesia}
|
||||
|
||||
| News | Kantar Scoop | Video Series | Podcast | Ready, Steady, Shop! | Asia Pulse |
|
||||
| ---- | ----------------------------- | ----------------- | ------------ | ------------------------ | --------------- |
|
||||
| News | News/Kantar-Worldpanel-Series | News/video-series | News/podcast | News/asia-shopper-series | News/Asia-Pulse |
|
||||
|
||||
#### Korea {#kantar-worldpanel-news-centre-korea}
|
||||
|
||||
| News | Insight Reports | In the Media |
|
||||
| ---- | --------------- | -------------- |
|
||||
| news | publications | press-releases |
|
||||
|
||||
#### Malaysia {#kantar-worldpanel-news-centre-malaysia}
|
||||
|
||||
| News |
|
||||
| ---- |
|
||||
| news |
|
||||
|
||||
#### Philippines {#kantar-worldpanel-news-centre-philippines}
|
||||
|
||||
| Latest Insights | In the Media | Events |
|
||||
| --------------- | ------------ | ------ |
|
||||
| Latest-Insights | In-the-Media | events |
|
||||
|
||||
#### Taiwan {#kantar-worldpanel-news-centre-taiwan}
|
||||
|
||||
| 聚焦台灣 | WOW SPOT | 市場報告 | 媒體報導 | 活動 |
|
||||
| ------------------------ | ------------ | ------------ | -------------- | ------ |
|
||||
| news/spotlight-on-taiwan | news/wowspot | publications | press-releases | events |
|
||||
|
||||
#### Thailand {#kantar-worldpanel-news-centre-thailand}
|
||||
|
||||
| News |
|
||||
| ---- |
|
||||
| news |
|
||||
|
||||
#### Vietnam {#kantar-worldpanel-news-centre-vietnam}
|
||||
|
||||
| Insights | FMCG Monitor | Ready, Steady, Shop! | Asia Pulse | IN THE MEDIA |
|
||||
| -------- | ----------------- | ---------------------- | --------------- | ------------ |
|
||||
| news | news/FMCG-Monitor | news/ready-steady-shop | news/asia-pulse | In-the-media |
|
||||
|
||||
</details>
|
||||
|
||||
</Route>
|
||||
|
||||
## KBS {#kbs}
|
||||
|
||||
### News {#kbs-news}
|
||||
|
|
|
|||
Loading…
Reference in New Issue