UNPKG

rsshub

Version:
59 lines (57 loc) 1.75 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; //#region lib/routes/instagram/common-utils.ts init_esm_shims(); const renderItems = (items) => items.map((item) => { const productType = item.product_type; const summary = item.caption?.text ?? ""; let description = ""; switch (productType) { case "carousel_container": { const images = item.carousel_media.map((i) => ({ ...i.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0], alt: item.accessibility_caption })); description = art(path.join(__dirname, "templates/images-105c7ff0.art"), { summary, images }); break; } case "clips": case "igtv": description = art(path.join(__dirname, "templates/video-fb8df18d.art"), { summary, image: item.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0], video: item.video_versions[0] }); break; case "feed": { const images = [{ ...item.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0], alt: item.accessibility_caption }]; description = art(path.join(__dirname, "templates/images-105c7ff0.art"), { summary, images }); break; } default: throw new Error(`Instagram: Unhandled feed type: ${productType}`); } const url = `https://www.instagram.com/p/${item.code}/`; const pubDate = parseDate(item.caption?.created_at_utc || item.taken_at, "X"); return { title: summary.split("\n")[0], id: item.pk, pubDate, author: item.user.username, link: url, summary, description }; }); //#endregion export { renderItems as t };