rsshub
Version:
Make RSS Great Again!
68 lines (67 loc) • 1.91 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { load } from "cheerio";
//#region lib/routes/zju/list.ts
const host = "https://www.zju.edu.cn/";
const route = {
path: "/list/:type",
categories: ["university"],
example: "/zju/list/xs",
parameters: { type: "`xs`为学术,`xw`为新闻,`5461`是图片新闻,`578`是浙大报道,具体参数参考左侧的菜单" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "普通栏目 如学术 / 图片 / 新闻等",
maintainers: ["Jeason0228"],
handler
};
async function handler(ctx) {
const type = ctx.req.param("type") ?? "xs";
const link = host + type + "/list.htm";
const $ = load((await got_default({
method: "get",
url: link,
headers: { Referer: host }
})).data);
function sortUrl(e) {
return e.search("redirect") === -1 ? e : link;
}
const list = $("#wp_news_w7 ul.news li").toArray().map((element) => {
return {
title: $(element).find("a").attr("title"),
link: sortUrl($(element).find("a").attr("href")),
date: $(element).text().match(/\d{4}-\d{2}-\d{2}/)[0]
};
});
const out = await Promise.all(list.map((info) => {
const title = info.title;
const date = info.date;
const itemUrl = new URL(info.link, host).href;
return cache_default.tryGet(itemUrl, async () => {
const description = load((await got_default({
method: "get",
url: itemUrl,
headers: { Referer: link }
})).data)(".right_content").html();
return {
title,
link: itemUrl,
description,
pubDate: parseDate(date)
};
});
}));
return {
title: "浙江大学" + $("ul.submenu .selected").text(),
link,
item: out
};
}
//#endregion
export { route };