UNPKG

rsshub

Version:
74 lines (72 loc) 2.86 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 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/tass/news.ts const route = { path: "/:category?", categories: ["traditional-media"], example: "/tass/politics", parameters: { category: "Category, can be found in URL, `politics` by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["tass.com/:category"], target: "/:category" }], name: "News", maintainers: ["TonyRL"], handler, description: `| Russian Politics & Diplomacy | World | Business & Economy | Military & Defense | Science & Space | Emergencies | Society & Culture | Press Review | Sports | | ---------------------------- | ----- | ------------------ | ------------------ | --------------- | ----------- | ----------------- | ------------ | ------ | | politics | world | economy | defense | science | emergencies | society | pressreview | sports |` }; async function handler(ctx) { const { category = "politics" } = ctx.req.param(); const { data: categoryPage, url: link } = await got_default(`https://tass.com/${category}`); const $ = load(categoryPage); const sectionId = $(".container .section-page").attr("ng-init").match(/sectionId\s*=\s*(\d+?);/); const { data: response } = await got_default.post("https://tass.com/userApi/categoryNewsList", { json: { sectionId: sectionId[1], limit: 20, type: "all" } }); const list = response.newsList.map((item) => ({ title: item.title, description: item.lead, link: `https://tass.com${item.link}`, pubDate: parseDate(item.date, "X") })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const { data: response$1 } = await got_default(item.link); const $$1 = load(response$1); $$1(".news-media img").each((_, ele) => { if (ele.attribs.src) ele.attribs.src = ele.attribs.src.replaceAll("/width/1020_b9261fa1", ""); }); item.description = $$1(".news-header__lead").prop("outerHTML") + ($$1(".news-media").prop("outerHTML") ?? "") + $$1(".text-block").html(); return item; }))); return { title: $("head title").text(), link, language: "en", image: $("head meta[property=\"og:image\"]").attr("content"), icon: $("head link[rel=\"apple-touch-icon\"]").attr("href"), logo: $("head link[rel=\"apple-touch-icon\"]").attr("href"), item: items }; } //#endregion export { route };