rsshub
Version:
Make RSS Great Again!
45 lines (44 loc) • 1.53 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/daodu/index.ts
const route = {
path: "/:caty?",
categories: ["new-media"],
example: "/daodu",
parameters: { caty: "分類,默認為全部" },
name: "分類",
maintainers: ["nczitzk"],
description: `| 全部 | 文章 | Podcast |
| ---- | ------- | ------- |
| all | article | podcast |`,
handler
};
async function handler(ctx) {
const { caty = "all" } = ctx.req.param();
const rootUrl = "https://daodu.tech";
const currentUrl = `${rootUrl}${caty === "all" ? "" : `/archive_${caty}`}`;
const $ = load(await rofetch(currentUrl));
const list = $("h2[itemprop=\"headline\"] a, .post-header .archive__article__title a").toArray().slice(0, 15).map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: new URL($item.attr("href").split("%3F", 1)[0], rootUrl).href
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
content(".member-only").remove();
item.description = content(".post-entry-text").html();
item.pubDate = parseDate(content("meta[property=\"article:published_time\"]").attr("content"));
return item;
})));
return {
title: $("title").text().replace("一覽表", ""),
link: currentUrl,
item: items
};
}
//#endregion
export { route };