rsshub
Version:
Make RSS Great Again!
48 lines (47 loc) • 1.49 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/wenxuecity/blog.ts
const route = {
path: "/blog/:id",
categories: ["bbs"],
example: "/wenxuecity/blog/43626",
parameters: { id: "博客 ID, 可在 URL 中找到" },
radar: [{
source: ["blog.wenxuecity.com/myblog/:id", "blog.wenxuecity.com/myoverview/:id"],
target: "/blog/:id"
}],
name: "博客",
maintainers: ["changlan"],
handler
};
async function handler(ctx) {
const { id } = ctx.req.param();
const baseUrl = `https://blog.wenxuecity.com/myblog/${id}/all.html`;
const $ = load(await rofetch(baseUrl));
const author = $("strong#username").text();
const list = $("div.articleCell.BLK_j_linedot1").toArray().map((item) => {
const $item = $(item);
return {
title: $item.find("a").text(),
link: new URL($item.find("a").attr("href"), "https://blog.wenxuecity.com").href,
author,
pubDate: parseDate($item.find("span.atc_tm.BLK_txtc").text())
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link, { headers: { Referer: baseUrl } }));
return {
...item,
description: content("div.articalContent").html()
};
})));
return {
title: $("head > title").text(),
link: baseUrl,
item: out
};
}
//#endregion
export { route };