UNPKG

rsshub

Version:
79 lines (78 loc) 2.6 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 { t as timezone } from "./timezone-DE--ze1V.mjs"; import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs"; import { d as renderYoutube } from "./utils-BHA2zQME.mjs"; import { load } from "cheerio"; //#region lib/routes/unit-image/films.ts const route = { path: "/films/:type?", categories: ["design"], example: "/unit-image/films/vfx", parameters: { type: { description: "Films type", options: [ "vfx", "game-trailer", "commercials", "making-of", "events" ].map((value) => ({ value, label: value })) } }, radar: [{ source: ["www.unit-image.fr/films"], target: "/films" }], name: "Films", maintainers: ["MisteryMonster"], handler, url: "www.unit-image.fr/films" }; async function handler(ctx) { const { type } = ctx.req.param(); const baseUrl = "https://www.unit-image.fr"; const apiUrl = `${baseUrl}/wp-json/wp/v2`; const limit = ctx.req.query("limit") ? Math.trunc(Number(ctx.req.query("limit"))) : 10; let category; if (type) category = await cache_default.tryGet(`unit-image:category:${type}`, async () => { const categories = await rofetch(`${apiUrl}/categories`, { query: { slug: type } }); if (categories.length === 0) throw new InvalidParameterError(`Unknown type: ${type}`); return categories[0]; }); const posts = await rofetch(`${apiUrl}/project`, { query: { per_page: limit === 10 ? void 0 : limit, _embed: "", categories: category?.id } }); const items = await Promise.all(posts.map((post) => cache_default.tryGet(post.link, async () => { const $ = load(await rofetch(post.link)); const content = $("main"); content.find("style, noscript, input").remove(); content.find(".youtube-player").each((_, el) => { $(el).replaceWith(renderYoutube(true, $(el).attr("data-id"), void 0, void 0)); }); content.find(".comparison-img").each((_, el) => { const image = $(el).attr("style")?.match(/url\('(.+?)'\)/)?.[1]; $(el).replaceWith(image ? `<img src="${image}">` : ""); }); return { title: post.title.rendered, link: post.link, pubDate: timezone(parseDate(post.date_gmt), 0), description: content.html(), category: post._embedded["wp:term"].flat().map((term) => term.name) }; }))); return { title: `Unit Image Films${type ? ` - ${type}` : ""}`, link: category ? category.link : `${baseUrl}/films/`, description: "Unit Images Films", item: items }; } //#endregion export { route };