mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route/caixin): Fetch all blog articles. (#13522)
* feat(route/caixin): Fetch all blog articles. * . * Update doc. * Update lib/v2/caixin/blog.js * . ---------
This commit is contained in:
+71
-49
@@ -5,54 +5,76 @@ const { parseDate } = require('@/utils/parse-date');
|
||||
const { parseBlogArticle } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { column } = ctx.params;
|
||||
if (!isValidHost(column)) {
|
||||
throw Error('Invalid column');
|
||||
const { column, limit = 20 } = ctx.params;
|
||||
if (!column) {
|
||||
const { data } = await got('https://blog.caixin.com/blog-api/post/index', {
|
||||
searchParams: {
|
||||
page: 1,
|
||||
size: limit,
|
||||
},
|
||||
}).json();
|
||||
const posts = data.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.brief,
|
||||
author: item.authorName,
|
||||
link: item.postUrl.replace('http://', 'https://'),
|
||||
pubDate: parseDate(item.publishTime, 'x'),
|
||||
}));
|
||||
const items = await Promise.all(posts.map((item) => parseBlogArticle(item, ctx.cache.tryGet)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `财新博客 - 全部`,
|
||||
link: 'https://blog.caixin.com',
|
||||
// description: introduce,
|
||||
// image: avatar,
|
||||
item: items,
|
||||
};
|
||||
} else {
|
||||
if (!isValidHost(column)) {
|
||||
throw Error('Invalid column');
|
||||
}
|
||||
const link = `https://${column}.blog.caixin.com`;
|
||||
const { data: response } = await got(link);
|
||||
const $ = cheerio.load(response);
|
||||
const user = $('div.indexMainConri > script[type="text/javascript"]')
|
||||
.text()
|
||||
.substring('window.user = '.length + 1)
|
||||
.split(';')[0]
|
||||
.replaceAll(/\s/g, '');
|
||||
const authorId = user.match(/id:"(\d+)"/)[1];
|
||||
const authorName = user.match(/name:"(.*?)"/)[1];
|
||||
const avatar = user.match(/avatar:"(.*?)"/)[1];
|
||||
const introduce = user.match(/introduce:"(.*?)"/)[1];
|
||||
|
||||
const {
|
||||
data: { data },
|
||||
} = await got('https://blog.caixin.com/blog-api/post/posts', {
|
||||
searchParams: {
|
||||
page: 1,
|
||||
size: ctx.query.limit ? parseInt(ctx.query.limit) : 20,
|
||||
content: '',
|
||||
authorId,
|
||||
sort: 'publishTime',
|
||||
direction: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
const posts = data.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.brief,
|
||||
author: item.displayName,
|
||||
link: item.guid.replace('http://', 'https://'),
|
||||
pubDate: parseDate(item.publishTime, 'x'),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(posts.map((item) => parseBlogArticle(item, ctx.cache.tryGet)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `财新博客 - ${authorName}`,
|
||||
link,
|
||||
description: introduce,
|
||||
image: avatar,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
const link = `https://${column}.blog.caixin.com`;
|
||||
const { data: response } = await got(link);
|
||||
const $ = cheerio.load(response);
|
||||
const authorId = $('script[type="text/javascript"]')
|
||||
.text()
|
||||
.match(/window\.authorId = (\d+);/)[1];
|
||||
const authorName = $('script[type="text/javascript"]')
|
||||
.text()
|
||||
.match(/window\.authorName = "(.*)";/)[1];
|
||||
const avatar = $('script[type="text/javascript"]')
|
||||
.text()
|
||||
.match(/avatar: "(.*?)",/)[1];
|
||||
const introduce = $('script[type="text/javascript"]')
|
||||
.text()
|
||||
.match(/introduce: "(.*?)"\n/)[1];
|
||||
|
||||
const {
|
||||
data: { data },
|
||||
} = await got('https://blog.caixin.com/blog-api/post/posts', {
|
||||
searchParams: {
|
||||
page: 1,
|
||||
size: ctx.query.limit ? parseInt(ctx.query.limit) : 20,
|
||||
content: '',
|
||||
authorId,
|
||||
sort: 'publishTime',
|
||||
direction: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
const posts = data.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.brief,
|
||||
author: item.displayName,
|
||||
link: item.guid.replace('http://', 'https://'),
|
||||
pubDate: parseDate(item.publishTime, 'x'),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(posts.map((item) => parseBlogArticle(item, ctx.cache.tryGet)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `财新博客 - ${authorName}`,
|
||||
link,
|
||||
description: introduce,
|
||||
image: avatar,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/article', require('./article'));
|
||||
router.get('/blog/:column', require('./blog'));
|
||||
router.get('/blog/:column?', require('./blog'));
|
||||
router.get('/database', require('./database'));
|
||||
router.get('/k', require('./k'));
|
||||
router.get('/latest', require('./latest'));
|
||||
|
||||
@@ -373,7 +373,7 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t
|
||||
|
||||
### 用户博客 {#cai-xin-bo-ke-yong-hu-bo-ke}
|
||||
|
||||
<Route author="Maecenas" example="/caixin/blog/zhangwuchang" path="/caixin/blog/:column" paramsDesc={['博客名称,可在博客主页的 URL 找到']}>
|
||||
<Route author="Maecenas" example="/caixin/blog/zhangwuchang" path="/caixin/blog/:column?" paramsDesc={['博客名称,可在博客主页的 URL 找到']}>
|
||||
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user