UNPKG

rsshub

Version:
117 lines (115 loc) 2.79 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import { t as getData } from "./utils-as1OaLtK.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 rofetch(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 };