UNPKG

rsshub

Version:
52 lines (51 loc) 1.73 kB
import { t as logger } from "./logger-DlhSwgkg.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as got_default } from "./got-DUpa1V3-.mjs"; import { load } from "cheerio"; //#region lib/routes/enterprisecraftsmanship/index.ts const route = { path: "/archives", categories: ["blog"], example: "/enterprisecraftsmanship/archives", radar: [{ source: ["enterprisecraftsmanship.com/archives/"] }], url: "enterprisecraftsmanship.com/", name: "Archives", maintainers: ["liyaozhong"], handler, description: "Enterprise Craftsmanship blog archives" }; async function handler() { const currentUrl = `https://enterprisecraftsmanship.com/archives`; const response = await got_default(currentUrl); const $ = load(response.data); let items = $(".postIndexItem").toArray().map((item) => { const $item = $(item); const title = $item.find(".title a").text().trim(); const link = new URL($item.find(".title a").attr("href"), currentUrl).href; const dateStr = $item.find(".date").text().trim(); return { title, link, pubDate: parseDate(dateStr) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const detailResponse = await got_default(item.link); const $detail = load(detailResponse.data); item.description = ($detail(".post > .paragraph").html() ?? "") + ($detail(".post >.sect1").html() ?? ""); return item; } catch (error) { logger.error(`处理文章 ${item.link} 时发生错误: ${error}`); return item; } }))); return { title: "Enterprise Craftsmanship - Archives", link: currentUrl, item: items }; } //#endregion export { route };