rsshub
Version:
Make RSS Great Again!
75 lines (74 loc) • 2.54 kB
JavaScript
import "./types-DNj6Etbg.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { n as topicDataHanding, t as constructTopicEntry } from "./utils-CX2kWfWL.mjs";
import dayjs from "dayjs";
import { load } from "cheerio";
//#region lib/routes/jike/topic.ts
const urlRegex = /(https?:\/\/[^\s"'<>]+)/g;
const route = {
path: "/topic/:id/:showUid?",
categories: ["social-media"],
view: 1,
example: "/jike/topic/556688fae4b00c57d9dd46ee",
parameters: {
id: "圈子 id, 可在即刻 web 端圈子页或 APP 分享出来的圈子页 URL 中找到",
showUid: {
description: "是否在内容中显示用户信息,设置为 1 则开启",
options: [{
value: "1",
label: "显示"
}]
}
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["web.okjike.com/topic/:id"],
target: "/topic/:id"
}, {
source: ["m.okjike.com/topics/:id"],
target: "/topic/:id"
}],
name: "圈子",
maintainers: ["DIYgod", "prnake"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const data = await constructTopicEntry(ctx, `https://m.okjike.com/topics/${id}`);
if (data) {
const result = data.result;
result.item = topicDataHanding(data, ctx);
if (id === "553870e8e4b0cafb0a1bef68" || id === "55963702e4b0d84d2c30ce6f") result.item = await Promise.all(result.item.map(async (one) => {
const item = { ...one };
const regResult = /https:\/\/www\.okjike\.com\/medium\/[\dA-Za-z]*/.exec(item.description);
if (regResult) {
const newsUrl = regResult[0];
item.description = await cache_default.tryGet(newsUrl, async () => {
const { data } = await got_default(newsUrl);
const $ = load(data);
const upper = $("ul.main > li.item");
const links = upper.find("a").map((_, ele) => $(ele).attr("href"));
const texts = upper.find("span.text").map((_, ele) => $(ele).text());
let description = "";
for (let i = 0; i < links.length; i++) description += `${i + 1}、<a href="${links[i]}">${texts[i]}</a><br>`;
description = description.replace(/<br>$/, "");
return description;
});
}
item.description = item.description.replaceAll(urlRegex, (url) => `<a href="${url}">${url}</a>`);
item.title = `${data.topic.content} ${dayjs(one.pubDate).format("MM月DD日")}`;
return item;
}));
return result;
}
}
//#endregion
export { route };