UNPKG

rsshub

Version:
49 lines (48 loc) 1.84 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { load } from "cheerio"; //#region lib/routes/chicagotribune/index.ts const route = { path: "/:category/:subcategory?", categories: ["traditional-media"], example: "/chicagotribune/news/nation", parameters: { category: "Category", subcategory: "Subcategory" }, radar: [{ source: ["www.chicagotribune.com/:category/:subcategory?"] }], name: "News", maintainers: ["oppilate"], description: `Generates full-text that the official feed doesn't provide. For instance, \`https://www.chicagotribune.com/news/national/\` corresponds to \`/chicagotribune/news/national\`.`, handler, url: "www.chicagotribune.com" }; async function handler(ctx) { const { category, subcategory } = ctx.req.param(); const baseUrl = "https://www.chicagotribune.com"; const link = `${baseUrl}/${category}/${subcategory ? `${subcategory}/` : ""}`; const $ = load(await rofetch(link)); const categoryId = $("body").attr("class")?.match(/\bcategory-(\d+)\b/)?.[1]; if (!categoryId) throw new Error(`Cannot find category id for ${link}`); const items = (await rofetch(`${baseUrl}/wp-json/wp/v2/posts`, { query: { categories: categoryId, _embed: "" } })).map((post) => ({ title: post.title.rendered, description: post.content.rendered, link: post.link, guid: post.guid.rendered, pubDate: parseDate(post.date_gmt), author: post.authors?.map((author) => author.display_name).join(", "), category: post._embedded?.["wp:term"]?.flat().filter((term) => term.taxonomy === "category").map((term) => term.name) })); return { title: $("head title").text(), description: $("meta[name=\"description\"]").attr("content"), link, language: $("html").attr("lang"), item: items }; } //#endregion export { route };