UNPKG

rsshub

Version:
129 lines (127 loc) 3.87 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import { t as ViewType } from "./types-D84BRIt4.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/augmentcode/blog.ts init_esm_shims(); const handler = async (ctx) => { const limit = Number.parseInt(ctx.req.query("limit") ?? "50", 10); const baseUrl = "https://augmentcode.com"; const targetUrl = new URL("blog", baseUrl).href; const $ = load(await ofetch_default(targetUrl)); const language = $("html").attr("lang") ?? "en"; let items = []; items = $("div[data-slot=\"card\"]").slice(0, limit).toArray().map((el) => { const $el = $(el); const title$1 = $el.find("div[data-slot=\"card-content\"]").text(); const pubDateStr = $el.find("div[data-slot=\"card-footer\"] p").last().text(); const linkUrl = $el.parent().attr("href"); const authors = $el.find("div[data-slot=\"card-footer\"] p").first().find("span").toArray().map((authorEl) => { return { name: $(authorEl).contents().first().text(), url: void 0, avatar: void 0 }; }); const image = $el.find("div[data-slot=\"card-header\"] img").attr("src"); const upDatedStr = pubDateStr; return { title: title$1, pubDate: pubDateStr ? parseDate(pubDateStr) : void 0, link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0, author: authors, image, banner: image, updated: upDatedStr ? parseDate(upDatedStr) : void 0, language }; }); items = await Promise.all(items.map((item) => { if (!item.link) return item; return cache_default.tryGet(item.link, async () => { const $$ = load(await ofetch_default(item.link)); const title$1 = $$("article h1").text(); const image = $$("meta[property=\"og:image\"]").attr("content") ?? item.image; const description = art(path.join(__dirname, "templates/description-16be3a2a.art"), { images: image ? [{ src: image, alt: title$1 }] : void 0, description: $$("div.prose").html() }); const pubDateStr = $$("meta[property=\"article:published_time\"]").attr("content"); const authors = $$("meta[property=\"article:author\"]").toArray().map((authorEl) => { return { name: $$(authorEl).attr("content"), url: void 0, avatar: void 0 }; }); const upDatedStr = pubDateStr; const processedItem = { title: title$1, description, pubDate: pubDateStr ? parseDate(pubDateStr) : item.pubDate, author: authors, content: { html: description, text: description }, image, banner: image, updated: upDatedStr ? parseDate(upDatedStr) : item.updated, language }; return { ...item, ...processedItem }; }); })); const title = $("title").text(); return { title, description: $("meta[name=\"description\"]").attr("content"), link: targetUrl, item: items, allowEmpty: true, image: $("meta[property=\"og:image\"]").attr("content"), author: title.split(/-/).pop()?.trim(), language, id: targetUrl }; }; const route = { path: "/blog", name: "Blog", url: "augmentcode.com", maintainers: ["nczitzk"], handler, example: "/augmentcode/blog", parameters: void 0, description: void 0, categories: ["programming"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["augmentcode.com/blog"], target: "/blog" }], view: ViewType.Articles }; //#endregion export { handler, route };