UNPKG

rsshub

Version:
76 lines (74 loc) 2.29 kB
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 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/uw/gix/news.ts const gixBaseURL = "https://gixnetwork.org"; const route = { path: "/gix/news/:category", categories: ["university"], example: "/uw/gix/news/blog", parameters: { category: "Blog Type" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["gixnetwork.org/news/:category"] }], name: "Global Innovation Exchange News", maintainers: ["dykderrick"], handler, description: `| Blog | In The News | | ---- | ----------- | | blog | inthenews |` }; async function handler(ctx) { const category = ctx.req.param("category"); let newsURL = gixBaseURL + "/news"; let feedTitle = "UW GIX News - "; let listSelector = "body > div.site > div.site-content > div.content-area > main.site-main > "; switch (category) { case "blog": newsURL += "/blog/"; feedTitle += "Blogs"; listSelector += "div.blog-wrapper > section.blog-list > article"; break; case "inthenews": newsURL += "/inthenews/"; feedTitle += "In The News"; listSelector += "div.news-wrapper > section.news-list > article"; break; } const data = (await got_default(newsURL)).data; const $ = load(data); const list = $(listSelector).toArray().map((item) => { item = $(item); const content = item.find("header").find("h2").find("a"); return { time: item.find("header").find("span.h4").text(), link: content.attr("href") }; }); const itemContent = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default(item.link)).data); item.title = content("header.entry-header").find("h1").text(); item.description = content("div.entry-content").html(); item.pubDate = Date.parse(item.time); return item; }))); return { title: feedTitle, link: newsURL, item: itemContent }; } //#endregion export { route };