diff --git a/lib/v2/zhihu/maintainer.js b/lib/v2/zhihu/maintainer.js index b7071060b1..8c2cdc42ac 100644 --- a/lib/v2/zhihu/maintainer.js +++ b/lib/v2/zhihu/maintainer.js @@ -16,6 +16,8 @@ module.exports = { '/topic/:topicId': ['xyqfer'], '/weekly': ['LogicJake'], '/xhu/collection/:id': ['JimenezLi'], + '/xhu/people/activities/:hexId': ['JimenezLi'], + '/xhu/people/answers/: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 ed051f7cb1..d0833cb803 100644 --- a/lib/v2/zhihu/radar.js +++ b/lib/v2/zhihu/radar.js @@ -80,6 +80,24 @@ module.exports = { source: '/column/:id', target: '/zhihu/zhuanlan/:id', }, + { + title: 'xhu - 用户动态', + docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu', + source: '/people/:id', + target: (params, url, document) => { + const hexId = /"id":"(.*?)"/.exec(document.getElementById('js-initialData').innerHTML)[1]; + return `/zhihu/xhu/people/activities/${hexId}`; + }, + }, + { + title: 'xhu - 用户回答', + docs: 'https://docs.rsshub.app/routes/social-media#zhi-hu', + source: '/people/:id/answers', + target: (params, url, document) => { + const hexId = /"id":"(.*?)"/.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', diff --git a/lib/v2/zhihu/router.js b/lib/v2/zhihu/router.js index 4e09cd9f79..bdeea3fe3d 100644 --- a/lib/v2/zhihu/router.js +++ b/lib/v2/zhihu/router.js @@ -16,6 +16,8 @@ module.exports = (router) => { router.get('/topic/:topicId', require('./topic')); router.get('/weekly', require('./weekly')); 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/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/activities.js b/lib/v2/zhihu/xhu/activities.js new file mode 100644 index 0000000000..4e44f6e7a0 --- /dev/null +++ b/lib/v2/zhihu/xhu/activities.js @@ -0,0 +1,112 @@ +const got = require('@/utils/got'); +const auth = require('./auth'); +const utils = require('../utils'); +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}`; + const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/activities?before_id=0&limit=20`; + + 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].actor.name}的知乎动态`, + link, + image: data[0].actor.avatar_url, + description: data[0].actor.headline || data[0].actor.description, + item: data.map((item) => { + const detail = item.target; + let title; + let description; + let url; + const images = []; + let text = ''; + let link = ''; + let author = ''; + + switch (item.target.type) { + case 'answer': + title = detail.question.title; + author = detail.author.name; + description = utils.ProcessImage(detail.content); + url = `https://www.zhihu.com/question/${detail.question.id}/answer/${detail.id}`; + break; + case 'article': + title = detail.title; + author = detail.author.name; + description = utils.ProcessImage(detail.content); + url = `https://zhuanlan.zhihu.com/p/${detail.id}`; + break; + case 'pin': + title = detail.excerpt_title; + author = detail.author.name; + detail.content.forEach((contentItem) => { + if (contentItem.type === 'text') { + text = `

${contentItem.own_text}

`; + } else if (contentItem.type === 'image') { + images.push(`

`); + } else if (contentItem.type === 'link') { + link = `

${contentItem.title}

`; + } else if (contentItem.type === 'video') { + link = `

`; + } + }); + description = `${text}${link}${images.join('')}`; + url = `https://www.zhihu.com/pin/${detail.id}`; + break; + case 'question': + title = detail.title; + author = detail.author.name; + description = utils.ProcessImage(detail.detail); + url = `https://www.zhihu.com/question/${detail.id}`; + break; + case 'collection': + title = detail.title; + url = `https://www.zhihu.com/collection/${detail.id}`; + break; + case 'column': + title = detail.title; + description = `

${detail.intro}

`; + url = `https://zhuanlan.zhihu.com/${detail.id}`; + break; + case 'topic': + title = detail.name; + description = `

${detail.introduction}

话题关注者人数:${detail.followers_count}

`; + url = `https://www.zhihu.com/topic/${detail.id}`; + break; + case 'live': + title = detail.subject; + description = detail.description.replace(/\n|\r/g, '
'); + url = `https://www.zhihu.com/lives/${detail.id}`; + break; + case 'roundtable': + title = detail.name; + description = detail.description; + url = `https://www.zhihu.com/roundtable/${detail.id}`; + break; + } + + return { + title: `${data[0].actor.name}${item.action_text}: ${title}`, + author, + description, + pubDate: parseDate(item.created_time * 1000), + link: url, + }; + }), + }; +}; diff --git a/lib/v2/zhihu/xhu/answers.js b/lib/v2/zhihu/xhu/answers.js new file mode 100644 index 0000000000..d6b6d42d61 --- /dev/null +++ b/lib/v2/zhihu/xhu/answers.js @@ -0,0 +1,31 @@ +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}/answers`; + const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/answers?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, + item: data.map((item) => ({ + title: item.question.title, + description: item.excerpt, + pubDate: parseDate(item.created_time * 1000), + link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`, + })), + }; +}; diff --git a/website/docs/routes/social-media.mdx b/website/docs/routes/social-media.mdx index 1b7bfda507..6c66161602 100644 --- a/website/docs/routes/social-media.mdx +++ b/website/docs/routes/social-media.mdx @@ -1746,18 +1746,32 @@ YouTube provides official RSS feeds for channels, for instance [https://www.yout ::: -### [xhu](https://github.com/REToys/xhu) - 收藏夹 {#zhi-hu-shou-cang-jia} +### [xhu](https://github.com/REToys/xhu) - 用户动态 {#zhi-hu-xhu-yong-hu-dong-tai} - + + :::tip + 用户的 16 进制 id 获取方式: + 1. 可以通过 RSSHub Radar 扩展获取; + 2. 或者在用户主页打开 F12 控制台,执行以下代码:`console.log(/"id":"(.*?)"/.exec(document.getElementById("js-initialData").innerHTML)[1]);` 即可获取用户的 16 进制 id。 + ::: + -### [xhu](https://github.com/REToys/xhu) - 专栏 {#zhi-hu-zhuan-lan} +### [xhu](https://github.com/REToys/xhu) - 用户回答{#zhi-hu-xhu-yong-hu-hui-da} - + -### [xhu](https://github.com/REToys/xhu) - 问题 {#zhi-hu-wen-ti} +### [xhu](https://github.com/REToys/xhu) - 收藏夹 {#zhi-hu-xhu-shou-cang-jia} - + -### [xhu](https://github.com/REToys/xhu) - 话题 {#zhi-hu-hua-ti} +### [xhu](https://github.com/REToys/xhu) - 专栏 {#zhi-hu-xhu-zhuan-lan} - + + +### [xhu](https://github.com/REToys/xhu) - 问题 {#zhi-hu-xhu-wen-ti} + + + +### [xhu](https://github.com/REToys/xhu) - 话题 {#zhi-hu-xhu-hua-ti} + +