mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): youzhiyouxing/materials get full text and refactor to V2 (#9082)
This commit is contained in:
+7
-1
@@ -277,7 +277,13 @@ pageClass: routes
|
||||
|
||||
### 有知文章
|
||||
|
||||
<Route author="broven" example="/youzhiyouxing/materials" path="/youzhiyouxing/materials" />
|
||||
<Route author="broven Fatpandac" example="/youzhiyouxing/materials" path="/youzhiyouxing/materials/:column?" :paramsDesc="['分类,见下表,默认为全部']">
|
||||
|
||||
| 全部 | 知行小酒馆 | 知行黑板报 | 无人知晓 | 孟岩专栏 | 知行读书会 | 你好,同路人 |
|
||||
| :--: | :--------: | :--------: | :------: | :------: | :--------: | :----------: |
|
||||
| 0 | 4 | 2 | 10 | 1 | 3 | 11 |
|
||||
|
||||
</Route>
|
||||
|
||||
## 证券时报网
|
||||
|
||||
|
||||
+1
-2
@@ -2057,8 +2057,7 @@ router.get('/weidian/goods/:id', lazyloadRouteHandler('./routes/weidian/goods'))
|
||||
|
||||
// 有赞
|
||||
router.get('/youzan/goods/:id', lazyloadRouteHandler('./routes/youzan/goods'));
|
||||
// 有知有行
|
||||
router.get('/youzhiyouxing/materials', lazyloadRouteHandler('./routes/youzhiyouxing/materials'));
|
||||
|
||||
// 币世界快讯
|
||||
router.get('/bishijie/kuaixun', lazyloadRouteHandler('./routes/bishijie/kuaixun'));
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = `https://youzhiyouxing.cn/materials`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('[phx-click=material]');
|
||||
const resData = {
|
||||
title: '有知有行 - 有知',
|
||||
link,
|
||||
description: '有知有行 - 有知',
|
||||
item: list
|
||||
.map((_index, item) => {
|
||||
const $item = $(item);
|
||||
const res = {
|
||||
title: $item.find('.title-bar > h3').text(),
|
||||
description: $item.find('.sm-text').text(),
|
||||
link: `https://youzhiyouxing.cn/materials/${$item.attr('phx-value-id')}`,
|
||||
};
|
||||
return res;
|
||||
})
|
||||
.get(),
|
||||
};
|
||||
ctx.state.data = resData;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/materials/:column?': ['broven', 'Fatpandac'],
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const rootUrl = 'https://youzhiyouxing.cn';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const column = ctx.params.column ?? '0';
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
||||
const url = `${rootUrl}/materials?column=${column}&limit=${limit}`;
|
||||
|
||||
const response = await got(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
const title = $(`a[phx-value-column="${column}"]`).text() === '' ? '全部' : $(`a[phx-value-column="${column}"]`).text();
|
||||
const list = $('[phx-click=material]')
|
||||
.map((_, item) => ({
|
||||
title: $(item).find('h3').text(),
|
||||
link: `${rootUrl}/materials/${$(item).attr('phx-value-id')}`,
|
||||
pubDate: parseDate($(item).find('div.xs-text.muted-text.tw-text-right').text(), ['YYYY年M月D日', 'M月D日']),
|
||||
}))
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('#zx-rangy-root')
|
||||
.html()
|
||||
.replace(/(<img.*?) src(=.*?>)/g, '$1 data$2')
|
||||
.replace(/(<img.*?) data-src(=.*?>)/g, '$1 src$2');
|
||||
item.author = content('span.tw-inline').text().replace('·', '');
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `有知有行 - ${title}`,
|
||||
link: url,
|
||||
description: `有知有行 - ${title}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
module.exports = {
|
||||
'youzhiyouxing.cn': {
|
||||
_name: '有知有行',
|
||||
'.': [
|
||||
{
|
||||
title: '有知 - 全部',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: '/youzhiyouxing/materials',
|
||||
},
|
||||
{
|
||||
title: '有知 - 知行小酒馆',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '4') {
|
||||
return '/youzhiyouxing/materials/4';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '有知 - 知行黑板报',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '2') {
|
||||
return '/youzhiyouxing/materials/2';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '有知 - 无人知晓',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '10') {
|
||||
return '/youzhiyouxing/materials/10';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '有知 - 孟岩专栏',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '1') {
|
||||
return '/youzhiyouxing/materials/1';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '有知 - 知行读书会',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '3') {
|
||||
return '/youzhiyouxing/materials/3';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '有知 - 你好,同路人',
|
||||
docs: 'https://docs.rsshub.app/finance.html#you-you-wei-zhi-zhi-you-you-wei-xing-hang-xing-hang-heng-you-you-wei-zhi-zhi-wen-zhang-zhang',
|
||||
source: ['/materials'],
|
||||
target: (_params, url) => {
|
||||
if (new URL(url).searchParams.get('column') === '11') {
|
||||
return '/youzhiyouxing/materials/11';
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/materials/:column?', require('./materials'));
|
||||
};
|
||||
Reference in New Issue
Block a user