rsshub
Version:
Make RSS Great Again!
99 lines (96 loc) • 3.25 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 { load } from "cheerio";
//#region lib/routes/hubu/index.ts
const handler = async (ctx) => {
const { category = "index/tzgg" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20;
const rootUrl = "https://www.hubu.edu.cn";
const currentUrl = new URL(`${category}.htm`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const language = $("html").prop("lang");
let items = $("div.list ul li").slice(0, limit).toArray().map((item) => {
item = $(item);
return {
title: item.find("a").text(),
pubDate: parseDate(item.find("span").text()),
link: new URL(item.find("a").prop("href"), rootUrl).href,
language
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
try {
const { data: detailResponse } = await got_default(item.link);
const $$ = load(detailResponse);
const title$1 = $$("div.con-tit h4").text();
if (!title$1) return item;
const description = $$("div.v_news_content").html();
item.title = title$1;
item.description = description;
item.category = $$("META[Name=\"keywords\"]").toArray().map((c) => $$(c).text());
item.content = {
html: description,
text: $$("div.v_news_content").text()
};
item.language = language;
} catch {}
return item;
})));
const title = $("title").text();
const image = new URL($("div.logo a img").prop("src"), rootUrl).href;
return {
title,
description: $("META[Name=\"keywords\"]").prop("content"),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: title.split(/-/).pop(),
language
};
};
const route = {
path: "/www/:category{.+}?",
name: "主页",
url: "hubu.edu.cn",
maintainers: ["nczitzk"],
handler,
example: "/hubu/www/index/tzgg",
parameters: { category: "分类,可在对应分类页 URL 中找到,默认为[通知公告](https://www.hubu.edu.cn/index/tzgg.htm)" },
description: `::: tip
若订阅 [通知公告](https://www.hubu.edu.cn/index/tzgg.htm),网址为 \`https://www.hubu.edu.cn/index/tzgg.htm\`。截取 \`https://www.hubu.edu.cn/\` 到末尾 \`.htm\` 的部分 \`index/tzgg\` 作为参数填入,此时路由为 [\`/hubu/www/index/tzgg\`](https://rsshub.app/hubu/www/index/tzgg)。
:::
| 通知公告 | 学术预告 |
| ---------- | ---------- |
| index/tzgg | index/xsyg |
`,
categories: ["university"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
title: "通知公告",
source: ["hubu.edu.cn/index/tzgg.htm"],
target: "/www/index/tzgg"
}, {
title: "学术预告",
source: ["hubu.edu.cn/index/xsyg.htm"],
target: "/www/index/xsyg"
}]
};
//#endregion
export { handler, route };