rsshub
Version:
Make RSS Great Again!
59 lines (58 loc) • 1.69 kB
JavaScript
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { n as parseContent, t as cnuFetch } from "./utils-6zKP85u_.mjs";
import { load } from "cheerio";
//#region lib/routes/cnu.cc/discovery.ts
const types = {
hot: "热门",
recommend: "推荐",
recent: "最新"
};
const route = {
path: "/discovery/:type?/:category?",
categories: ["picture"],
example: "/cnu.cc/discovery/hot",
parameters: {
type: "板块类型, 默认为`热门`, 具体参见下表",
category: "图片类别, 默认为`0`代表全部, 可参见[这里](http://www.cnu.cc/discoveryPage/hot-0)"
},
name: "发现",
maintainers: ["hoilc"],
description: `| 热门 | 推荐 | 最新 |
| ---- | --------- | ------ |
| hot | recommend | recent |`,
handler
};
async function handler(ctx) {
const { type = "hot", category = "0" } = ctx.req.param();
const url = `http://www.cnu.cc/discoveryPage/${type}-${encodeURIComponent(category)}`;
const $ = load(await cnuFetch(url));
const list = $(".grid-item.work-thumbnail").toArray().map((item) => {
const $item = $(item);
return {
title: $item.find(".title").text().trim(),
link: $item.find("a.thumbnail").attr("href")
};
});
const out = await Promise.all(list.map(async (item) => {
try {
return await cache_default.tryGet(item.link, async () => {
const result = parseContent(await cnuFetch(item.link));
return {
...item,
author: result.author,
description: result.description,
pubDate: result.pubDate
};
});
} catch {
return null;
}
}));
return {
title: `CNU视觉联盟 - ${types[type]}`,
link: url,
item: out.filter((item) => item !== null)
};
}
//#endregion
export { route };