UNPKG

rsshub

Version:
59 lines (57 loc) 1.71 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 "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/atcoder/post.ts const route = { path: "/post/:language?/:keyword?", categories: ["programming"], example: "/atcoder/post", parameters: { language: "Language, `jp` as Japanese or `en` as English, English by default", keyword: "Keyword" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Posts", maintainers: ["nczitzk"], handler }; async function handler(ctx) { const language = ctx.req.param("language") ?? "en"; const keyword = ctx.req.param("keyword") ?? ""; const rootUrl = "https://atcoder.jp"; const currentUrl = `${rootUrl}/posts?lang=${language}${keyword ? `&keyword=${keyword}` : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); const items = $(".panel").toArray().map((item) => { item = $(item); return { title: item.find(".panel-title").text(), description: item.find(".panel-body").html(), link: `${rootUrl}${item.find(".panel-title a").attr("href")}`, pubDate: timezone(parseDate(item.find(".timeago").attr("datetime")), 9) }; }); return { title: `${keyword ? `[${keyword}] - ` : ""}${$("title").text()}`, link: currentUrl, item: items }; } //#endregion export { route };