UNPKG

rsshub

Version:
150 lines (148 loc) 5.95 kB
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/infoq/presentations.ts init_esm_shims(); const handler = async (ctx) => { const { conference } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 12; const rootUrl = "https://www.infoq.com"; const currentUrl = new URL(`${conference ? `${conference}/` : ""}presentations/`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); const language = $("html").prop("lang"); let items = $("ul[data-tax=\"presentations\"] li[data-path]").slice(0, limit).toArray().map((item) => { item = $(item); const a = item.find("h3.card__title a"); const title$1 = a.prop("title") || a.text().trim(); const image$1 = item.find("img.card__image").prop("src"); const description = art(path.join(__dirname, "templates/description-36fefaf3.art"), { images: image$1 ? [{ src: image$1, alt: title$1 }] : void 0, intro: item.find("p.card__excerpt").text() }); const link = new URL(a.prop("href"), rootUrl).href; const guid = `infoq-${item.prop("data-path").replace(/^\//, "")}`; const length = item.find("div.card__length").text() || void 0; return { title: title$1, description, pubDate: parseDate(item.find("span.card__date span").text().trim()), link, category: item.find("div.card__topics").toArray().map((c) => $(c).text().trim()), author: item.find("div.card__authors a").toArray().map((a$1) => $(a$1).text().trim()).join("/"), guid, id: guid, content: { html: description, text: item.find("p.card__excerpt").text() }, image: image$1, banner: image$1, language, enclosure_url: length ? link : void 0, enclosure_type: length ? "video/mp4" : void 0, enclosure_title: title$1, itunes_duration: length }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const $$ = load(detailResponse); $$("div.player").prevAll().remove(); $$("div.event__list-box").remove(); const length = $$("div.player__actions span").text() || void 0; const script = $$("script[type=\"text/javascript\"]").text(); const videoSrc = script.match(/P\.s\s=\s'(.*?)';/)?.[1] ?? void 0; const poster = script.match(/P\.c\(.*?isWideScreen,\s'(.*?)',\s/)?.[1] ?? void 0; const topicsStr = script.match(/var\stopicsInPage\s=\sJSON\.parse\('(.*?)'\);/)?.[1]?.replaceAll("\\", "") ?? void 0; if (videoSrc) $$("div.player").replaceWith(art(path.join(__dirname, "templates/description-36fefaf3.art"), { videos: [{ src: videoSrc, poster, type: `video/${videoSrc.split(/\./).pop()}` }] })); const title$1 = $$("meta[property=\"og:title\"]").prop("content").trim(); const image$1 = $$("meta[property=\"twitter:image\"]").prop("content") || $$("meta[property=\"og:image\"]").prop("content"); item.title = title$1; item.pubDate = parseDate($$("p.date").text()); item.link = $$("meta[property=\"og:url\"]").prop("content"); item.category = topicsStr ? JSON.parse(topicsStr).map((t) => t.name) : $$("meta[name=\"keywords\"]").prop("content").split(/,/); item.author = $$("ul.authors a.author__link").toArray().map((a) => $$(a).text()).join("/"); $$("div.article__content").nextAll().remove(); const description = art(path.join(__dirname, "templates/description-36fefaf3.art"), { images: image$1 ? [{ src: image$1, alt: title$1 }] : void 0, description: $$("article.article").html() }); item.description = description; item.content = { html: description, text: $$("article.article").text() }; item.image = image$1; item.banner = image$1; item.language = language; item.enclosure_url = videoSrc; item.enclosure_type = item.enclosure_url ? "video/mp4" : void 0; item.enclosure_title = title$1; item.itunes_duration = length; return item; }))); const title = $("title").text(); const image = $("meta[property=\"og:image\"]").prop("content"); return { title, description: $("meta[name=\"description\"]").prop("content"), link: currentUrl, item: items, allowEmpty: true, image, author: title.split(/-/).pop(), language }; }; const route = { path: "/presentations/:conference?", name: "Presentations", url: "www.infoq.com", maintainers: ["nczitzk"], handler, example: "/infoq/presentations", parameters: { conference: "Conference, all by default, can be found in URL" }, description: `::: tip If you subscribe to [InfoQ Live Jan 2024](https://www.infoq.com/infoq-live-jan-2024/presentations/),where the URL is \`https://www.infoq.com/infoq-live-jan-2024/presentations/\`, extract the part \`https://www.infoq.com/\` to the end, which is \`/presentations/\`, and use it as the parameter to fill in. Therefore, the route will be [\`/infoq/presentations/infoq-live-jan-2024\`](https://rsshub.app/infoq/presentations/infoq-live-jan-2024). ::: `, categories: ["programming"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.infoq.com/presentations", "www.infoq.com/:conference/presentations"], target: (params) => { const conference = params.conference; return `/presentations${conference ? `/${conference}` : ""}`; } }] }; //#endregion export { handler, route };