UNPKG

rsshub

Version:
47 lines (46 loc) 1.87 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { n as renderItem, t as apiUrl } from "./utils-DHxwL3MR.mjs"; //#region lib/routes/technologyreview/topic.ts const route = { path: "/:category_name", categories: ["journal"], example: "/technologyreview/artificial-intelligence", parameters: { category_name: "see below" }, description: `| Category | \`:category_name\` | | ------------------------- | ----------------------- | | Artificial intelligence | artificial-intelligence | | Biotechnology and health | biotechnology | | Business | business | | Climate change and energy | climate-change | | Computing | computing | | Culture | culture | | Policy | policy | | Space | space |`, radar: [{ source: ["www.technologyreview.com/topic/:category_name"], target: "/:category_name" }], name: "Topics", maintainers: ["laampui"], handler, url: "www.technologyreview.com" }; async function handler(ctx) { const { category_name: categoryName } = ctx.req.param(); const categories = await cache_default.tryGet(`technologyreview:category:${categoryName}`, () => rofetch(`${apiUrl}/categories`, { query: { slug: categoryName } })); const limit = Number(ctx.req.query("limit") ?? 10); const posts = await rofetch(`${apiUrl}/posts`, { query: { categories: categories[0].id, per_page: limit === 10 ? void 0 : limit, _embed: "" } }); return { title: `${categories[0].name} | MIT Technology Review`, link: `https://www.technologyreview.com/topic/${categoryName}/`, language: "en-us", item: posts.map((item) => renderItem(item)) }; } //#endregion export { route };