rsshub
Version:
Make RSS Great Again!
38 lines (37 loc) • 1.3 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 { t as timezone } from "./timezone-DE--ze1V.mjs";
import { load } from "cheerio";
//#region lib/routes/lixin/utils.ts
async function fetchMain(url, dataElement) {
const $ = load(await rofetch(url));
return {
list: $(dataElement).toArray().map((item) => {
const $item = $(item);
return {
href: $item.children("a").attr("href"),
publishDate: $item.children("span").text()
};
}),
title: $("title").text()
};
}
function fetchDetail(list, baseUrl, contentElement) {
return Promise.all(list.map((item) => {
const href = item.href.startsWith("http") ? item.href : baseUrl + item.href;
return cache_default.tryGet(href, async () => {
const $ = load(await rofetch(href));
let description = $(contentElement).html();
if (!description) description = `无法解析公告, 这可能是因为这是一个外部链接或者文件. 请<a href="${href}">点击查看</a>`;
return {
title: $("title").text(),
link: href,
description,
pubDate: timezone(parseDate(item.publishDate, "YYYY-MM-DD"), 8)
};
});
}));
}
//#endregion
export { fetchMain as n, fetchDetail as t };