feat(route): add 厦门网新闻 (#13868)

* feat(route): add 厦门网新闻

* fix url
This commit is contained in:
Ethan Shen
2023-11-24 00:25:48 +08:00
committed by GitHub
parent 291d3ee3da
commit dd1fcefbf0
6 changed files with 153 additions and 2 deletions
View File
+1
View File
@@ -1,3 +1,4 @@
module.exports = {
'/epaper/:id?': ['nczitzk'],
'/news/:category?': ['nczitzk'],
};
+65
View File
@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { category = 'xmxw' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
const rootUrl = 'https://news.xmnn.cn';
const currentUrl = new URL(`${category}/`, rootUrl).href;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
let items = $('div#sort_body ul li a')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('h1').text().trim(),
link: item.prop('href'),
description: item.find('div.abstract').html(),
author: item.find('div.source').text(),
pubDate: timezone(parseDate(item.find('div.time').text()), +8),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = cheerio.load(detailResponse);
item.title = content('div.cont-h, div.tip h1').text().trim();
item.description = content('div.TRS_Editor').html();
item.author = content('span.cont-a-src a')
.toArray()
.map((a) => content(a).text());
item.pubDate = timezone(parseDate(content('span.time, div.pubtime div.w').contents().first().text().trim()), +8);
return item;
})
)
);
const title = $('title').text();
const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href;
ctx.state.data = {
item: items,
title,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh',
icon,
logo: icon,
subtitle: $('div.h').text(),
author: title.split(/_/).pop(),
};
};
+67 -1
View File
@@ -5,9 +5,75 @@ module.exports = {
{
title: '数字媒体',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-shu-zi-mei-ti',
source: ['/:id', '/'],
source: ['/:id'],
target: '/xmnn/epaper/:id',
},
],
news: [
{
title: '新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/:category*'],
target: (params) => {
const category = params.category;
return `/xmnn/news/${category ? `/${category}` : ''}`;
},
},
{
title: '厦门新闻发布',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/xmxwfb'],
target: '/xmnn/news/xmxwfb',
},
{
title: '厦门新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/xmxw'],
target: '/xmnn/news/xmxw',
},
{
title: '本网快报',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/bwkb'],
target: '/xmnn/news/bwkb',
},
{
title: '厦门网眼',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/xmwy'],
target: '/xmnn/news/xmwy',
},
{
title: '福建新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/fjxw'],
target: '/xmnn/news/fjxw',
},
{
title: '国内新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/gnxw'],
target: '/xmnn/news/gnxw',
},
{
title: '国际新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/gjxw'],
target: '/xmnn/news/gjxw',
},
{
title: '台海新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/thxw'],
target: '/xmnn/news/thxw',
},
{
title: '社会新闻',
docs: 'https://docs.rsshub.app/routes/traditional-media#xia-men-wang-xin-wen',
source: ['/shxw'],
target: '/xmnn/news/shxw',
},
],
},
};
+1
View File
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/epaper/:id?', require('./epaper'));
router.get('/news/:category*', require('./news'));
};
+19 -1
View File
@@ -2302,7 +2302,7 @@ category 对应的关键词有
### 数字媒体 {#xia-men-wang-shu-zi-mei-ti}
<Route author="nczitzk" example="/xmnn/epaper/xmrb" path="/xmnn/epaper/:id?" paramsDesc={['报纸 id,见下表,默认为 `xmrb`,即厦门日报']}>
<Route author="nczitzk" example="/xmnn/epaper/xmrb" path="/xmnn/epaper/:id?" paramsDesc={['报纸 id,见下表,默认为 `xmrb`,即厦门日报']} radar="1" rssbud="1">
| 厦门日报 | 厦门晚报 | 海西晨报 | 城市捷报 |
| -------- | -------- | -------- | -------- |
@@ -2310,6 +2310,24 @@ category 对应的关键词有
</Route>
### 新闻 {#xia-men-wang-xin-wen}
<Route author="nczitzk" example="/xmnn/news/xmxw" path="/xmnn/news/:category?" paramsDesc={['分类 id,见下表,默认为厦门新闻']} radar="1" rssbud="1">
| 分类名 | 分类 id |
| ------------ | ------- |
| 厦门新闻发布 | xmxwfb |
| 厦门新闻 | xmxw |
| 本网快报 | bwkb |
| 厦门网眼 | xmwy |
| 福建新闻 | fjxw |
| 国内新闻 | gnxw |
| 国际新闻 | gjxw |
| 台海新闻 | thxw |
| 社会新闻 | shxw |
</Route>
## 四川广播电视台 {#si-chuan-guang-bo-dian-shi-tai}
### 电视回放 {#si-chuan-guang-bo-dian-shi-tai-dian-shi-hui-fang}