rsshub
Version:
Make RSS Great Again!
77 lines (75 loc) • 2.83 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/vice/topic.ts
init_esm_shims();
const render = (data) => art(path.join(__dirname, "templates/article-383a87b9.art"), data);
const route = {
path: "/topic/:topic/:language?",
categories: ["traditional-media"],
example: "/vice/topic/politics/en",
parameters: {
topic: "Can be found in the URL",
language: "defaults to `en`, use the website to discover other codes"
},
radar: [{
source: ["www.vice.com/:language/topic/:topic"],
target: "/topic/:topic/:language"
}],
name: "Topic",
maintainers: ["K33k0"],
handler,
url: "vice.com/"
};
async function handler(ctx) {
const { language = "en", topic } = ctx.req.param();
const $ = load(await ofetch_default(`https://www.vice.com/${language}/topic/${topic}`));
const list = JSON.parse($("script#__NEXT_DATA__").text()).props.pageProps.listPageData.articles.map((item) => ({
title: item.title,
link: `https://vice.com${item.url}`,
pubDate: parseDate(item.publish_date, "x"),
author: item.contributions.map((c) => c.contributor.full_name).join(", "),
description: item.dek,
category: [...new Set([item.primary_topic.name, ...item.topics.map((t) => t.name)])]
}));
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const $$1 = load(await ofetch_default(item.link));
const articleNextData = JSON.parse($$1("script#__NEXT_DATA__").text()).props.pageProps.data.articles[0];
const bodyComponent = JSON.parse(articleNextData.body_components_json);
item.description = render({ image: {
url: articleNextData.thumbnail_url,
alt: articleNextData.caption,
caption: articleNextData.caption,
credit: articleNextData.credit
} }) + bodyComponent.map((component) => {
switch (component.role) {
case "body": return render({ body: { html: component.html } });
case "heading2": return render({ heading2: { html: component.html } });
case "image": return render({ image: {
url: component.URL,
alt: component.alt,
caption: component.caption
} });
case "oembed":
case "tweet":
case "youtube": return render({ oembed: { html: component.oembed.html } });
default: return "";
}
}).join("");
return item;
})));
return {
title: `VICE | ${topic} articles`,
link: `https://vice.com/${language}/topic/${topic}`,
item: items
};
}
//#endregion
export { route };