feat(route): add 差评快讯 and refactor to V2 (#9319)

* feat(route): add 差评快讯 and refactor to V2

* fix: parseDate
This commit is contained in:
Fatpandac 2022-03-15 02:30:06 +08:00 committed by GitHub
parent 9dc20280e8
commit ea0022cbcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 7 deletions

View File

@ -1496,6 +1496,10 @@ Supported sub-sites:
</Route>
### 快讯
<Route author="Fatpandac" example="/chaping/newsflash" path="/chaping/newsflash"/>
## 城农 Growin' City
### 城农资讯观点

View File

@ -3211,10 +3211,6 @@ router.get('/blogs/jianning', lazyloadRouteHandler('./routes/blogs/jianning'));
// 互动吧
router.get('/hudongba/:city/:id', lazyloadRouteHandler('./routes/hudongba/index'));
// 差评
router.get('/chaping/banner', lazyloadRouteHandler('./routes/chaping/banner'));
router.get('/chaping/news/:caty?', lazyloadRouteHandler('./routes/chaping/news'));
// 飞雪娱乐网
router.get('/feixuew/:id?', lazyloadRouteHandler('./routes/feixuew/index'));

View File

@ -1,4 +1,5 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = `https://chaping.cn/`;
@ -24,7 +25,7 @@ module.exports = async (ctx) => {
item.description = content.content;
item.author = content.article_author.name;
item.pubDate = new Date(content.time_publish_timestamp * 1000).toUTCString();
item.pubDate = parseDate(content.time_publish_timestamp * 1000);
return item;
})

View File

@ -0,0 +1,5 @@
module.exports = {
'/banner': ['nczitzk'],
'/news/:caty?': ['nczitzk'],
'/newsflash': ['Fatpandac'],
};

View File

@ -1,4 +1,5 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const titles = {
0: '全部',
@ -13,7 +14,7 @@ const titles = {
};
module.exports = async (ctx) => {
ctx.params.caty = ctx.params.caty || '';
ctx.params.caty = ctx.params.caty ?? '';
const targetUrl = `https://chaping.cn/news?cate=${ctx.params.caty}`;
const currentUrl = `https://chaping.cn/api/official/information/news?page=1&limit=16&cate=${ctx.params.caty}`;
@ -25,7 +26,7 @@ module.exports = async (ctx) => {
const list = apiResponse.data.data.map((item) => ({
title: item.title,
link: `https://chaping.cn/news/${item.id}`,
pubDate: new Date(item.time_publish_timestamp * 1000).toUTCString(),
pubDate: parseDate(item.time_publish_timestamp * 1000),
}));
const items = await Promise.all(

View File

@ -0,0 +1,23 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const host = 'https://chaping.cn';
module.exports = async (ctx) => {
const newflashAPI = `${host}/api/official/information/newsflash?page=1&limit=21`;
const response = await got(newflashAPI).json();
const data = response.data;
ctx.state.data = {
title: '差评 快讯',
link: `${host}/newsflash`,
item:
data &&
data.map((item) => ({
title: item.title,
description: item.summary,
pubDate: parseDate(item.time_publish_timestamp * 1000),
link: item.origin_url,
})),
};
};

31
lib/v2/chaping/radar.js Normal file
View File

@ -0,0 +1,31 @@
module.exports = {
'chaping.cn': {
_name: '差评',
'.': [
{
title: '图片墙',
docs: 'https://docs.rsshub.app/new-media.html#cha-ping',
source: ['/'],
target: '/chaping/banner',
},
{
title: '资讯',
docs: 'https://docs.rsshub.app/new-media.html#cha-ping',
source: ['/news'],
target: (params, url) => {
const cateList = ['15', '3', '7', '5', '6', '1', '8', '9'];
const cate = new URL(url).searchParams.get('cate');
if (cateList.includes(cate)) {
return `/chaping/news/${cate}`;
}
},
},
{
title: '快讯',
docs: 'https://docs.rsshub.app/new-media.html#cha-ping',
source: ['/newsflash'],
target: '/chaping/newsflash',
},
],
},
};

5
lib/v2/chaping/router.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = function (router) {
router.get('/banner', require('./banner'));
router.get('/news/:caty?', require('./news'));
router.get('/newsflash', require('./newsflash'));
};