UNPKG

rsshub

Version:
72 lines (71 loc) 2.84 kB
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as isWorker } from "./is-worker-Dkdjp-Po.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { n as processImage, r as withZhihuClient } from "./utils-B6B0m8Xx.mjs"; //#region lib/routes/zhihu/posts.ts const route = { path: "/posts/:usertype/:id", categories: ["social-media"], example: "/zhihu/posts/people/frederchen", parameters: { usertype: "作者 id,可在用户主页 URL 中找到", id: "用户类型usertype,参考用户主页的URL。目前有两种,见下表" }, features: { requireConfig: [{ name: "ZHIHU_COOKIES", description: "A complete d_c0 and __zse_ck cookie pair skips session initialization. Otherwise Workers use a Playwright browser session; Docker and Vercel generate credentials with JSDOM.", optional: true }], requirePuppeteer: isWorker || process.env.WORKER_BUILD === "true", antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.zhihu.com/:usertype/:id/posts", "www.zhihu.com/:usertype/:id"] }], name: "用户文章", maintainers: ["whtsky", "Colin-XKL"], handler, description: `| 普通用户 | 机构用户 | | -------- | -------- | | people | org |` }; function handler(ctx) { const id = ctx.req.param("id"); const usertype = ctx.req.param("usertype"); return withZhihuClient(`https://www.zhihu.com/${usertype}/${id}/posts`, async (client) => { const userProfile = await cache_default.tryGet(`zhihu:posts:profile:${id}`, async () => { const profileApiPath = `/api/v4/members/${id}`; const result = await client.get(profileApiPath); return { name: result.name, headline: result.headline, avatarUrl: result.avatar_url }; }); const apiPath = `/api/v4/members/${id}/articles?${new URLSearchParams({ include: "data[*].comment_count,suggest_edit,is_normal,thumbnail_extra_info,thumbnail,can_comment,comment_permission,admin_closed_comment,content,voteup_count,created,updated,upvoted_followees,voting,review_info,reaction_instruction,is_labeled,label_info;data[*].vessay_info;data[*].author.badge[?(type=best_answerer)].topics;data[*].author.vip_info;", offset: "0", limit: "20", sort_by: "created" })}`; const items = (await client.get(apiPath)).data.map((item) => ({ title: item.title, description: processImage(item.content), link: `https://zhuanlan.zhihu.com/p/${item.id}`, pubDate: parseDate(item.created, "X"), updated: parseDate(item.updated, "X"), author: item.author.name })); return { title: `${userProfile.name} 的知乎文章`, link: `https://www.zhihu.com/${usertype}/${id}/posts`, description: userProfile.headline, image: userProfile.avatarUrl.split("?", 1)[0], item: items }; }); } //#endregion export { route };