rsshub
Version:
Make RSS Great Again!
92 lines (90 loc) • 2.69 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
//#region lib/routes/dedao/knowledge.ts
init_esm_shims();
const route = {
path: "/knowledge/:topic?/:type?",
categories: ["new-media"],
example: "/dedao/knowledge",
parameters: {
topic: "话题 id,可在对应话题页 URL 中找到",
type: "分享类型,`true` 指精选,`false` 指最新,默认为精选"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: [
"dedao.cn/knowledge/topic/:topic",
"dedao.cn/knowledge",
"dedao.cn/"
] }],
name: "知识城邦",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const topic = ctx.req.param("topic") ?? "";
const type = /t|y/i.test(ctx.req.param("type") ?? "true");
const count = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 100;
const rootUrl = "https://www.dedao.cn";
const currentUrl = `${rootUrl}/knowledge${topic === "" ? "" : "/topic/" + topic}`;
const apiUrl = `${rootUrl}/pc/ledgers/${topic === "" ? "notes/friends_timeline" : "topic/notes/list"}`;
const detailUrl = `${rootUrl}/pc/ledgers/topic/detail`;
let title = "", description = "";
if (topic !== "") {
const detailResponse = await got_default({
method: "post",
url: detailUrl,
json: {
incr_view_count: false,
topic_id_hazy: topic
}
});
title = detailResponse.data.c.name;
description = detailResponse.data.c.intro;
}
const response = await got_default({
method: "post",
url: apiUrl,
json: {
count,
load_chain: true,
is_elected: type,
page_id: 0,
topic_id_hazy: topic,
version: 2
}
});
const items = (topic === "" ? response.data.c.notes : response.data.c.note_detail_list).map((item) => ({
title: item.f_part.note,
author: item.f_part.nick_name,
link: `${rootUrl}/knowledge/note/${item.f_part.note_id_hazy}`,
pubDate: parseDate(item.f_part.time_desc, "MM-DD"),
description: art(path.join(__dirname, "templates/knowledge-72d39b85.art"), {
rootUrl,
f_part: item.f_part,
s_part: item.s_part
})
}));
return {
title: `得到 - 知识城邦${title === "" ? "" : " - " + title}`,
link: currentUrl,
item: items,
description
};
}
//#endregion
export { route };