rsshub
Version:
Make RSS Great Again!
47 lines (45 loc) • 1.97 kB
JavaScript
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { load } from "cheerio";
//#region lib/routes/jou/utils/index.ts
async function getItems(ctx, url, host, tableClass, timeStyleClass1, titleStyleClass, timeStyleClass2) {
const response = await ofetch_default(url);
if (!response) return [];
const $ = load(response);
const list = $(`table.${tableClass} > tbody > tr[height=20]`).toArray().map((item) => {
const currentItem = $(item);
const item1 = currentItem.find("td:eq(1)");
const item2 = currentItem.find("td:eq(2)");
const link = new URL(item1.find("a").attr("href"), host).href;
return {
title: item1.find("a").attr("title"),
link,
pubDate: timezone(parseDate(item2.find(`.${timeStyleClass1}`).text(), "YYYY-MM-DD"), 8)
};
});
return await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const response$1 = await ofetch_default(item.link);
if (!response$1 || response$1.status >= 300 && response$1.status < 400) return {
...item,
description: "该通知无法直接预览,请点击原文链接↑查看"
};
const $$1 = load(response$1);
item.title = $$1(`.${titleStyleClass}`).text();
if ($$1("script:contains(\"showVsbpdfIframe\")").length > 0) item.description = "该通知无法直接预览,请点击原文链接↑查看";
else {
const $content = load($$1(".v_news_content").html());
$content("a").each(function() {
const a = $$1(this);
const href = a.attr("href");
if (href && !href.startsWith("http")) a.attr("href", new URL(href, host).href);
});
item.description = $content.html();
}
item.pubDate = timezone(parseDate($$1(`.${timeStyleClass2}`).text().replace("发布时间:", "")), 8);
return item;
})));
}
//#endregion
export { getItems as t };