rsshub
Version:
Make RSS Great Again!
63 lines (62 loc) • 2.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 { t as timezone } from "./timezone-DE--ze1V.mjs";
import { load } from "cheerio";
//#region lib/routes/lit/xwzx.ts
const route = {
path: "/xwzx/:name?",
categories: ["university"],
example: "/lit/xwzx",
parameters: { name: "默认为 `all`" },
name: "新闻中心",
maintainers: ["vhxubo"],
description: `| 全部 | 公告通知 | 新闻快讯 | 学术信息 | 媒体新闻 |
| ---- | -------- | -------- | -------- | -------- |
| all | ggtz | xwkx | xsxx | mtxw |`,
handler
};
const host = "https://www.lit.edu.cn/";
const baseUrl = "https://www.lit.edu.cn/xwzx/";
const nameProps = {
ggtz: "公告通知",
xwkx: "新闻快讯",
xsxx: "学术信息",
mtxw: "媒体新闻"
};
async function handler(ctx) {
const { name = "all" } = ctx.req.param();
const categories = name === "all" ? Object.keys(nameProps) : [name];
const list = (await Promise.all(categories.map(async (category) => {
const link = new URL(`${category}.htm`, baseUrl).href;
const $ = load(await rofetch(link));
return $("li.notice-item").toArray().map((item) => {
const $item = $(item);
const [author, date] = $item.find(".notice-link-time").text().split(",", 2);
return {
title: $item.find(".notice-link-text").text(),
link: new URL($item.find("a.notice-link").attr("href"), link).href,
author: date ? author : void 0,
pubDate: timezone(parseDate(date ?? author), 8),
category: [nameProps[category]]
};
});
}))).flat().toSorted((a, b) => b.pubDate.getTime() - a.pubDate.getTime());
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
if (!item.link.startsWith(host)) return item;
const content = load(await rofetch(item.link))("form[name=\"_newscontent_fromname\"]");
item.title = content.find("h3").text();
item.description = content.find(".v_news_content").html();
const time = content.text().match(/\d{4}年\d{1,2}月\d{1,2}日 \d{1,2}:\d{1,2}/);
if (time) item.pubDate = timezone(parseDate(time[0], "YYYY年M月D日 H:mm"), 8);
return item;
})));
return {
title: name === "all" ? "新闻中心 - 洛阳理工学院" : `${nameProps[name]} - 洛理新闻中心`,
link: name === "all" ? baseUrl : new URL(`${name}.htm`, baseUrl).href,
description: "洛阳理工学院新闻中心 RSS",
item: items
};
}
//#endregion
export { route };