rsshub
Version:
Make RSS Great Again!
115 lines (113 loc) • 3.52 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.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 { t as timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/musikguru/news.ts
init_esm_shims();
const handler = async (ctx) => {
const limit = Number.parseInt(ctx.req.query("limit") ?? "10", 10);
const baseUrl = "https://musikguru.de";
const targetUrl = new URL("news/", baseUrl).href;
const $ = load(await ofetch_default(targetUrl));
const language = $("html").attr("lang") ?? "de";
let items = [];
items = $("section").eq(1).find("div.card").slice(0, limit).toArray().map((el) => {
const $el = $(el);
const title = $el.find("h5.card-title").text();
const image = $el.find("img").attr("src");
const description = art(path.join(__dirname, "templates/description-881baa33.art"), {
images: image ? [{
src: image,
alt: title
}] : void 0,
intro: $el.find("p.card-text").text()
});
const linkUrl = $el.find("a").first().attr("href");
return {
title,
description,
link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0,
content: {
html: description,
text: description
},
image,
banner: image,
language
};
});
items = await Promise.all(items.map((item) => {
if (!item.link) return item;
return cache_default.tryGet(item.link, async () => {
const $$ = load(await ofetch_default(item.link));
const title = $$("div.article h1").text();
const description = item.description + art(path.join(__dirname, "templates/description-881baa33.art"), { description: ($$("p.lead").html() ?? "") + ($$("div.lead").html() ?? "") });
const pubDateStr = $$("div.article div.text-muted").text().split(/\sUhr/)?.[0];
const image = $$("div.article img").first().attr("src");
const upDatedStr = pubDateStr;
const processedItem = {
title,
description,
pubDate: pubDateStr ? timezone(parseDate(pubDateStr, "DD.MM.YYYY HH:mm"), 1) : item.pubDate,
content: {
html: description,
text: description
},
image,
banner: image,
updated: upDatedStr ? timezone(parseDate(upDatedStr, "DD.MM.YYYY HH:mm"), 1) : item.updated,
language
};
return {
...item,
...processedItem
};
});
}));
return {
title: $("title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link: targetUrl,
item: items,
allowEmpty: true,
image: $("a.navbar-brand img").attr("src") ? new URL($("a.navbar-brand img").attr("src"), baseUrl).href : void 0,
author: $("a.navbar-brand img").attr("alt"),
language,
id: targetUrl
};
};
const route = {
path: "/news",
name: "News",
url: "musikguru.de",
maintainers: ["nczitzk"],
handler,
example: "/musikguru/news",
parameters: void 0,
description: void 0,
categories: ["multimedia"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["musikguru.de/news"],
target: "news"
}],
view: ViewType.Articles
};
//#endregion
export { handler, route };