feat(route): add PANews (#9116)

* feat(route): add PANews

* fix typo
This commit is contained in:
Ethan Shen
2022-02-19 16:57:52 +08:00
committed by GitHub
parent 8b8bd685a9
commit 00f641ca15
8 changed files with 272 additions and 0 deletions
+23
View File
@@ -833,6 +833,29 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route>
## PANews
### 深度
<Route author="nczitzk" example="/panewslab" path="/panewslab/:category?" :paramsDesc="['分类,见下表,默认为精选']">
| DAO | 元宇宙 | DeFi | Layer 2 | 链游 | 波卡 | NFT | 央行数字货币 | 融资 | 活动 | 监管 |
| --- | ------ | ---- | ------- | ---- | ---- | --- | ------------ | ---- | ---- | ---- |
</Route>
### 快讯
<Route author="nczitzk" example="/panewslab/newsflash" path="/panewslab/newsflash/:language?" :paramsDesc="['语言,默认为 zh,可在地址栏 URL 中找到']"/>
### 专栏
<Route author="nczitzk" example="/panewslab/column/N7042814" path="/panewslab/column/:id" :paramsDesc="['专栏 id,可在地址栏 URL 中找到']"/>
### 专题
<Route author="nczitzk" example="/panewslab/topic/1582623288184036" path="/panewslab/topic/:id" :paramsDesc="['专题 id,可在地址栏 URL 中找到']"/>
## PMCAFF
### 今日推荐 / 精选
+60
View File
@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://panewslab.com';
const apiUrl = `${rootUrl}/api/newstopic/page`;
const currentUrl = `${rootUrl}/zh/author/${id}.html`;
let author = '';
const response = await got({
method: 'post',
url: apiUrl,
form: {
memberId: id,
language: 'zh',
pageIndex: 1,
pageSize: 25,
newsTopicState: 'PUBLISHED',
},
});
let items = response.data.data.list.map((item) => {
author = item.nick_name;
return {
author,
title: item.title,
pubDate: parseDate(item.create_time),
link: `${rootUrl}/zh/articledetails/${item.id}.html`,
description: `<blockquote>${item.remark}</blockquote>`,
category: item.tags.split(','),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description += content('#txtinfo').html();
return item;
})
)
);
ctx.state.data = {
title: `PANews - ${author}`,
link: currentUrl,
item: items,
};
};
+56
View File
@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category ?? '';
const rootUrl = 'https://panewslab.com';
const apiUrl = `${rootUrl}/api/newstopic/page`;
const currentUrl = `${rootUrl}/zh/profundity/index.html`;
const response = await got({
method: 'post',
url: apiUrl,
form: {
language: 'zh',
pageIndex: 1,
pageSize: 25,
newsTopicState: 'PUBLISHED',
isEssence: 'T',
tags: category,
},
});
let items = response.data.data.list.map((item) => ({
title: item.title,
author: item.nick_name,
pubDate: parseDate(item.create_time),
link: `${rootUrl}/zh/articledetails/${item.id}.html`,
description: `<blockquote>${item.remark}</blockquote>`,
category: item.tags.split(','),
}));
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description += content('#txtinfo').html();
return item;
})
)
);
ctx.state.data = {
title: `PANews - ${category || '精选'}`,
link: currentUrl,
item: items,
};
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
'/column/:id': ['nczitzk'],
'/newsflash/:language?': ['nczitzk'],
'/topic/:id': ['nczitzk'],
'/:category?': ['nczitzk'],
};
+35
View File
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const language = ctx.params.language ?? 'zh';
const rootUrl = 'https://panewslab.com';
const apiUrl = `${rootUrl}/api/sqtopic/pageBy`;
const currentUrl = `${rootUrl}/${language}/news/index.html`;
const response = await got({
method: 'post',
url: apiUrl,
form: {
language,
pageIndex: 1,
pageSize: 50,
topicState: 'PUBLISHED',
},
});
const items = response.data.data.list[0].data.map((item) => ({
title: item.title,
author: item.nick_name,
pubDate: parseDate(item.create_time),
link: `${rootUrl}/${language}/sqarticledetails/${item.id}.html`,
description: `<p>${item.content.replace(/来源链接$/, '').replace(/原文链接$/, '')}</p>`,
}));
ctx.state.data = {
title: 'PANews - 快讯',
link: currentUrl,
item: items,
};
};
+31
View File
@@ -0,0 +1,31 @@
module.exports = {
'panewslab.com': {
_name: 'PANews',
'.': [
{
title: '深度',
docs: 'https://docs.rsshub.app/new-media.html#panews-shen-du',
source: '/',
target: '/panewslab/:category?',
},
{
title: '快讯',
docs: 'https://docs.rsshub.app/new-media.html#panews-kuai-xun',
source: '/',
target: '/panewslab/newsflash/:language?',
},
{
title: '专栏',
docs: 'https://docs.rsshub.app/new-media.html#panews-zhuan-lan',
source: '/',
target: '/panewslab/column/:id',
},
{
title: '专题',
docs: 'https://docs.rsshub.app/new-media.html#panews-zhuan-ti',
source: '/',
target: '/panewslab/topic/:id',
},
],
},
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = function (router) {
router.get('/column/:id', require('./column'));
router.get('/newsflash/:language?', require('./newsflash'));
router.get('/topic/:id', require('./topic'));
router.get('/:category?', require('./index'));
};
+55
View File
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://panewslab.com';
const apiUrl = `${rootUrl}/newstopic/pageH`;
const currentUrl = `${rootUrl}/zh/topiclist/${id}.html`;
const response = await got({
method: 'post',
url: apiUrl,
form: {
language: 'zh',
pageIndex: 1,
pageSize: 25,
newsThemeId: id,
newsTopicState: 'PUBLISHED',
},
});
let items = response.data.data.list.map((item) => ({
title: item.title,
author: item.nick_name,
pubDate: parseDate(item.create_time),
link: `${rootUrl}/zh/articledetails/${item.id}.html`,
description: `<blockquote>${item.remark}</blockquote>`,
category: item.tags.split(','),
}));
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description += content('#txtinfo').html();
return item;
})
)
);
ctx.state.data = {
title: `PANews - ${id}`,
link: currentUrl,
item: items,
};
};