rsshub
Version:
Make RSS Great Again!
68 lines (66 loc) • 2.11 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { URL } from "node:url";
import { load } from "cheerio";
//#region lib/routes/wzu/news.ts
const baseUrl = "http://www.wzu.edu.cn/index/";
const newsType = {
wdxw: "温大新闻",
mtwd: "媒体温大",
xswd: "学术温大",
tzgg: "通知公告",
zbxx: "招标信息",
xsgg: "学术公告"
};
/**
* @description: 抓取文章内容
* @param {*} link
* @return {*} description
*/
async function loadContent(link) {
let videoUrl = "";
const $ = load((await got_default.get(link)).data, { decodeEntities: false });
$("img").attr("src", (n, v) => new URL(v, baseUrl).href);
$(".vsbcontent_video").each(function() {
videoUrl = new URL($(this).find("script").attr("vurl"), baseUrl).href;
return $(this).html("<video width=\"100%\" src=\"" + videoUrl + "\"></video>").html();
});
return $("div[id^=vsb_content]").html();
}
const route = {
path: "/news/:type?",
name: "Unknown",
maintainers: ["Chandler-Lu"],
handler
};
async function handler(ctx) {
const routeTag = Number.parseInt(ctx.req.param("type")) || 0;
const [k1, newsTitle] = Object.entries(newsType)[routeTag];
const newsLink = new URL(k1 + ".htm", baseUrl).href;
const list = load((await got_default.get(newsLink)).data)("#News-sidebar-b-nav").find("li");
return {
title: newsTitle,
link: newsLink,
description: "温州大学 - " + newsTitle,
item: list.toArray().map(async (item) => {
const $ = load(item);
const $a1 = $("li>a");
const $itemUrl = new URL($a1.attr("href"), baseUrl).href;
return {
title: $a1.attr("title"),
description: await cache_default.tryGet($itemUrl, () => loadContent($itemUrl)),
pubDate: parseDate($("li>samp").text(), "YYYY-MM-DD"),
link: $itemUrl
};
})
};
}
//#endregion
export { route };