rsshub
Version:
Make RSS Great Again!
53 lines (51 loc) • 1.9 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { n as parseRelativeDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/zhishifenzi/innovation.ts
const route = {
path: "/innovation/:type?",
categories: ["study"],
example: "/zhishifenzi/innovation/company",
parameters: { type: "type,eg. company" },
name: "innovation",
maintainers: ["y9c"],
handler,
description: `| \`:type\` | type name |
| ------------- | ------------- |
| ~~multiple~~ | ~~Multiple~~ |
| company | Company |
| product | Product |
| technology | Technology |
| ~~character~~ | ~~Character~~ |
| policy | Policy |
> leave it blank(\`/zhishifenzi/innovation\`)to get all`
};
const base = "https://zhishifenzi.com";
async function handler(ctx) {
const { type } = ctx.req.param();
const link = type === void 0 ? `${base}/innovation` : `${base}/innovation/${type}`;
const $ = load(await rofetch(link));
const navTitle = $("div.innovation_nav > ul > li.sel").text().split(":").pop();
const title = navTitle === "" ? "全部創新" : `創新「${navTitle}」`;
const list = $("div.inner_news_list > ul > li.clearfix").toArray().slice(0, 4).map((elem) => {
const $elem = $(elem);
return {
title: $elem.find("div > h5 > a").text(),
pubDate: parseRelativeDate($elem.find("span").first().text()),
link: new URL($elem.find("div > h5 > a").attr("href"), base).href
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
item.description = load(await rofetch(item.link))(".main div.inner_content").html();
return item;
})));
return {
title: `知識分子 | ${title}`,
description: "知識分子 | 科學 文明 智慧",
link,
item: out
};
}
//#endregion
export { route };