fix(route): cnbeta (#11490)
This commit is contained in:
+4
-12
@@ -245,19 +245,11 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/cgtn/pick" path="/cgtn/pick"/>
|
||||
|
||||
## cnBeta
|
||||
## cnBeta.COM
|
||||
|
||||
### 最新
|
||||
### 头条资讯
|
||||
|
||||
<Route author="kt286 HaitianLiu nczitzk" example="/cnbeta" path="/cnbeta">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
最新的内容来源于 [官方 RSS](https://www.cnbeta.com/backend.php)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
<Route author="kt286 HaitianLiu nczitzk" example="/cnbeta" path="/cnbeta" />
|
||||
|
||||
### 分类
|
||||
|
||||
@@ -275,7 +267,7 @@ pageClass: routes
|
||||
|
||||
::: tip 提示
|
||||
|
||||
完整的主题列表参见 [主题列表](https://www.cnbeta.com/topics.htm)
|
||||
完整的主题列表参见 [主题列表](https://www.cnbeta.com.tw/topics.htm)
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
const parser = require('@/utils/rss-parser');
|
||||
|
||||
const { rootUrl, ProcessItems } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const currentUrl = `${rootUrl}/backend.php`;
|
||||
|
||||
let { items } = await parser.parseURL(currentUrl);
|
||||
items = items.filter((item) => item.link.includes('cnbeta'));
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'cnBeta',
|
||||
link: currentUrl,
|
||||
item: await ProcessItems(items, ctx.query.limit, ctx.cache.tryGet),
|
||||
};
|
||||
};
|
||||
@@ -1,22 +1,22 @@
|
||||
module.exports = {
|
||||
'cnbeta.com': {
|
||||
_name: 'cnBeta',
|
||||
'cnbeta.com.tw': {
|
||||
_name: 'cnBeta.COM',
|
||||
'.': [
|
||||
{
|
||||
title: '最新',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-zuixin',
|
||||
title: '头条资讯',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-com-tou-tiao-zi-xun',
|
||||
source: ['/'],
|
||||
target: '/cnbeta',
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-fenlei',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-com-fen-lei',
|
||||
source: ['/category/:id', '/'],
|
||||
target: '/cnbeta/category/:id',
|
||||
},
|
||||
{
|
||||
title: '主题',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-zhuti',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#cnbeta-com-zhu-ti',
|
||||
source: ['/topics/:id', '/'],
|
||||
target: '/cnbeta/topics/:id',
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/:type/:id', require('./type'));
|
||||
router.get('/', require('./index'));
|
||||
router.get('/', require('./type'));
|
||||
};
|
||||
|
||||
+6
-12
@@ -6,32 +6,26 @@ const { parseDate } = require('@/utils/parse-date');
|
||||
const { rootUrl, ProcessItems } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
const id = ctx.params.id;
|
||||
const { type, id } = ctx.params;
|
||||
|
||||
const currentUrl = `${rootUrl}/${type}/${id}.htm`;
|
||||
const currentUrl = type ? `${rootUrl}/${type}/${id}.htm` : rootUrl;
|
||||
|
||||
let response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
let response = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const token = encodeURI($('meta[name="csrf-token"]').attr('content'));
|
||||
const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').attr('data-type')}&page=1&_csrf=${token}&_=${new Date().getTime()}`;
|
||||
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
response = await got(apiUrl);
|
||||
|
||||
const items = response.data.result.list.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.hometext,
|
||||
author: item.source.split('@http')[0],
|
||||
pubDate: timezone(parseDate(item.inputtime), +8),
|
||||
link: item.url_show.indexOf('//') === 0 ? `https:${item.url_show}` : item.url_show,
|
||||
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
||||
category: item.label.name,
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const rootUrl = 'https://www.cnbeta.com';
|
||||
const rootUrl = 'https://www.cnbeta.com.tw';
|
||||
|
||||
module.exports = {
|
||||
rootUrl,
|
||||
ProcessItems: async (items, limit, tryGet) =>
|
||||
await Promise.all(
|
||||
items.slice(0, limit ? parseInt(limit) : 50).map((item) =>
|
||||
ProcessItems: (items, limit, tryGet) =>
|
||||
Promise.all(
|
||||
items.slice(0, limit ? parseInt(limit) : 60).map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const detailResponse = await got(item.link);
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user