feat(route): zhihu xhu posts (#14246)

This commit is contained in:
JimenezLi
2024-01-15 23:23:47 +08:00
committed by GitHub
parent 50b32696fa
commit 450bdb3a17
5 changed files with 51 additions and 2 deletions
+1
View File
@@ -18,6 +18,7 @@ module.exports = {
'/xhu/collection/:id': ['JimenezLi'],
'/xhu/people/activities/:hexId': ['JimenezLi'],
'/xhu/people/answers/:hexId': ['JimenezLi'],
'/xhu/people/posts/:hexId': ['JimenezLi'],
'/xhu/question/:questionId/:sortBy?': ['JimenezLi'],
'/xhu/topic/:topicId': ['JimenezLi'],
'/xhu/zhuanlan/:id': ['JimenezLi'],
+11 -2
View File
@@ -83,7 +83,7 @@ module.exports = {
{
title: 'xhu - 用户动态',
docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu',
source: '/people/:id',
source: ['/people/:id', '/org/:id'],
target: (params, url, document) => {
const hexId = /"id":"([0-9a-f]*?)","urlToken"/.exec(document.getElementById('js-initialData').innerHTML)[1];
return `/zhihu/xhu/people/activities/${hexId}`;
@@ -92,12 +92,21 @@ module.exports = {
{
title: 'xhu - 用户回答',
docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu',
source: '/people/:id/answers',
source: ['/people/:id/answers', '/org/:id/answers'],
target: (params, url, document) => {
const hexId = /"id":"([0-9a-f]*?)","urlToken"/.exec(document.getElementById('js-initialData').innerHTML)[1];
return `/zhihu/xhu/people/answers/${hexId}`;
},
},
{
title: 'xhu - 用户文章',
docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu',
source: ['/people/:id/posts', '/org/:id/posts'],
target: (params, url, document) => {
const hexId = /"id":"([0-9a-f]*?)","urlToken"/.exec(document.getElementById('js-initialData').innerHTML)[1];
return `/zhihu/xhu/people/posts/${hexId}`;
},
},
{
title: 'xhu - 收藏夹',
docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu',
+1
View File
@@ -18,6 +18,7 @@ module.exports = (router) => {
router.get('/xhu/collection/:id', require('./xhu/collection'));
router.get('/xhu/people/activities/:hexId', require('./xhu/activities'));
router.get('/xhu/people/answers/:hexId', require('./xhu/answers'));
router.get('/xhu/people/posts/:hexId', require('./xhu/posts'));
router.get('/xhu/question/:questionId/:sortBy?', require('./xhu/question'));
router.get('/xhu/topic/:topicId', require('./xhu/topic'));
router.get('/xhu/zhuanlan/:id', require('./xhu/zhuanlan'));
+34
View File
@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const auth = require('./auth');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const xhuCookie = await auth.getCookie(ctx);
const { hexId } = ctx.params;
const link = `https://www.zhihu.com/people/${hexId}/posts`;
const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/articles?limit=20&offset=0`;
const response = await got({
method: 'get',
url,
headers: {
Referer: 'https://api.zhihuvvv.workers.dev',
Cookie: xhuCookie,
},
});
const data = response.data.data;
ctx.state.data = {
title: `${data[0].author.name} 的知乎文章`,
link,
image: data[0].author.avatar_url,
description: data[0].author.headline,
item: data.map((item) => ({
title: item.title,
description: item.excerpt,
pubDate: parseDate(item.created * 1000),
link: `https://zhuanlan.zhihu.com/p/${item.id}`,
author: item.author.name,
})),
};
};
+4
View File
@@ -1673,6 +1673,10 @@ YouTube provides official RSS feeds for channels, for instance [https://www.yout
<Route author="JimenezLi" example="/zhihu/xhu/people/answers/246e6cf44e94cefbf4b959cb5042bc91" path="/zhihu/xhu/people/answers/:hexId" paramsDesc={['用户的 16 进制 id,获取方式同 [xhu - 用户动态](#zhi-hu-xhu-yong-hu-dong-tai)']} radar="1" />
### xhu - 用户文章 {#zhi-hu-xhu-yong-hu-wen-zhang}
<Route author="JimenezLi" example="/zhihu/xhu/people/posts/246e6cf44e94cefbf4b959cb5042bc91" path="/zhihu/xhu/people/posts/:hexId" paramsDesc={['用户的 16 进制 id,获取方式同 [xhu - 用户动态](#zhi-hu-xhu-yong-hu-dong-tai)']} radar="1" />
### xhu - 收藏夹 {#zhi-hu-xhu-shou-cang-jia}
<Route author="JimenezLi" example="/zhihu/xhu/collection/26444956" path="/zhihu/xhu/collection/:id" paramsDesc={['收藏夹 id, 可在收藏夹页面 URL 中找到']} radar="1" />