From 450bdb3a17082c0d2c57c07ea8aa96dcf1f7f04e Mon Sep 17 00:00:00 2001
From: JimenezLi <75196426+JimenezLi@users.noreply.github.com>
Date: Mon, 15 Jan 2024 23:23:47 +0800
Subject: [PATCH] feat(route): zhihu xhu posts (#14246)
---
lib/v2/zhihu/maintainer.js | 1 +
lib/v2/zhihu/radar.js | 13 +++++++++--
lib/v2/zhihu/router.js | 1 +
lib/v2/zhihu/xhu/posts.js | 34 ++++++++++++++++++++++++++++
website/docs/routes/social-media.mdx | 4 ++++
5 files changed, 51 insertions(+), 2 deletions(-)
create mode 100644 lib/v2/zhihu/xhu/posts.js
diff --git a/lib/v2/zhihu/maintainer.js b/lib/v2/zhihu/maintainer.js
index 8c2cdc42a..04a7672f1 100644
--- a/lib/v2/zhihu/maintainer.js
+++ b/lib/v2/zhihu/maintainer.js
@@ -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'],
diff --git a/lib/v2/zhihu/radar.js b/lib/v2/zhihu/radar.js
index fd7cfab2a..7dcf3e9ee 100644
--- a/lib/v2/zhihu/radar.js
+++ b/lib/v2/zhihu/radar.js
@@ -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',
diff --git a/lib/v2/zhihu/router.js b/lib/v2/zhihu/router.js
index bdeea3fe3..2cd942b60 100644
--- a/lib/v2/zhihu/router.js
+++ b/lib/v2/zhihu/router.js
@@ -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'));
diff --git a/lib/v2/zhihu/xhu/posts.js b/lib/v2/zhihu/xhu/posts.js
new file mode 100644
index 000000000..cceb648e6
--- /dev/null
+++ b/lib/v2/zhihu/xhu/posts.js
@@ -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,
+ })),
+ };
+};
diff --git a/website/docs/routes/social-media.mdx b/website/docs/routes/social-media.mdx
index 2fad79f99..ebdd6b6f3 100644
--- a/website/docs/routes/social-media.mdx
+++ b/website/docs/routes/social-media.mdx
@@ -1673,6 +1673,10 @@ YouTube provides official RSS feeds for channels, for instance [https://www.yout
+### xhu - 用户文章 {#zhi-hu-xhu-yong-hu-wen-zhang}
+
+
+
### xhu - 收藏夹 {#zhi-hu-xhu-shou-cang-jia}