UNPKG

rsshub

Version:
124 lines (121 loc) 2.75 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import "./cache-SV6W5EPy.mjs"; import { t as getData } from "./utils-CNKBtxNj.mjs"; //#region lib/routes/aeon/category.ts const route = { path: "/category/:category", categories: ["new-media"], example: "/aeon/category/philosophy", parameters: { category: { description: "Category", options: [ { value: "philosophy", label: "Philosophy" }, { value: "science", label: "Science" }, { value: "psychology", label: "Psychology" }, { value: "society", label: "Society" }, { value: "culture", label: "Culture" } ] } }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["aeon.co/:category"] }], name: "Categories", maintainers: ["emdoe"], handler }; const ENDPOINT = "https://api.aeonmedia.co/graphql"; const LIST_BY_SECTION = ` query getAeonArticlesBySection($section: String!, $sortField: ArticleSortEnum = published_at, $afterCursor: String, $tag: String) { section(site: aeon, slug: $section) { slug title metaDescription } articles( site: aeon section: $section status: [published] tag: $tag sort: {field: $sortField, order: desc} after: $afterCursor first: 24 ) { nodes { slug ...aeonArticleCardFragment } pageInfo { hasNextPage endCursor } } } fragment aeonArticleCardFragment on Article { id title slug type standfirstLong authors { name } image { url } primaryTopic { title } section { slug } } `; async function handler(ctx) { const category = ctx.req.param("category").toLowerCase(); const url = `https://aeon.co/category/${category}`; const response = await ofetch_default(ENDPOINT, { method: "POST", body: { operationName: "getAeonArticlesBySection", query: LIST_BY_SECTION, variables: { section: category } } }); const items = await getData(response.data.articles.nodes.map((node) => ({ title: node.title, description: node.standfirstLong, author: node.authors.map((author) => author.name).join(", "), link: `https://aeon.co/${node.type}s/${node.slug}`, category: node.primaryTopic.title, image: node.image.url, type: node.type, section: node.section.slug, slug: node.slug }))); return { title: `AEON | ${response.data.section.title}`, link: url, description: response.data.section.metaDescription, item: items }; } //#endregion export { route };