UNPKG

rsshub

Version:
76 lines (75 loc) 3.04 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { load } from "cheerio"; //#region lib/routes/shopify/engineering.ts const baseUrl = "https://shopify.engineering"; const route = { path: "/engineering/:topic?", categories: ["programming"], example: "/shopify/engineering", parameters: { topic: "Topic slug from `/topics/:topic`, e.g. `mobile`, `ai-machine-learning`. Defaults to the latest listing." }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["shopify.engineering/", "shopify.engineering/latest"], target: "/engineering" }, { source: ["shopify.engineering/topics/:topic"], target: "/engineering/:topic" }], name: "Engineering", maintainers: ["zhsama"], handler, url: "shopify.engineering/latest" }; async function handler(ctx) { const topic = ctx.req.param("topic"); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 20; const link = topic ? `${baseUrl}/topics/${topic}` : `${baseUrl}/latest`; const $ = load(await rofetch(link)); const list = $("main article").toArray().map((element) => { const $item = $(element); const $title = $item.find("a[href^=\"/\"]").not("[href^=\"/topics/\"]").filter((_, link) => /\S/.test($(link).text())); const href = $title.attr("href"); const category = $item.find("a[href^=\"/topics/\"]").text(); return { title: $title.text(), link: href ? new URL(href, baseUrl).href : void 0, category: category ? [category] : void 0 }; }).filter((item) => item.title && item.link).slice(0, limit); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $detail = load(await rofetch(item.link)); const $article = $detail("article[itemtype=\"https://schema.org/Article\"]"); const published = $article.find("meta[itemprop=\"datePublished\"]").attr("content"); const authors = [...new Set($article.find("a[href^=\"/authors/\"]").toArray().map((el) => $detail(el).text()).filter(Boolean))]; const content = $article.find("[itemprop=\"articleBody\"]"); content.find(".hidden, .leadpage-container").remove(); return { ...item, title: $article.find("[itemprop=\"headline\"]").text() || item.title, description: content.html() ?? $detail("meta[property=\"og:description\"]").attr("content"), pubDate: published ? parseDate(published) : item.pubDate, author: authors.join(", ") || void 0, image: $detail("meta[property=\"og:image\"]").attr("content") || void 0 }; }))); return { title: topic ? $("title").text() : "Shopify Engineering", link, description: $("meta[name=\"description\"]").attr("content"), image: "https://cdn.shopify.com/b/shopify-brochure2-assets/c97c60ca19c64a8b5378d9f9e971f7bd.png", language: "en-us", item: items }; } //#endregion export { route };