rsshub
Version:
Make RSS Great Again!
82 lines (73 loc) • 2.84 kB
JavaScript
import { t as rofetch } from "./ofetch-eUBdfMpp.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
import pMap from "p-map";
//#region lib/routes/europapress/index.ts
const route = {
path: "/:category?",
categories: ["new-media"],
example: "/europapress",
parameters: {
category: "Category, see below, Home by default",
limit: {
description: "Number of articles, 10 by default",
default: "10"
}
},
name: "Category",
maintainers: ["nczitzk"],
handler,
description: `Categories
| España | Internacional | Economía | Deportes |
| -------- | ------------- | -------- | -------- |
| nacional | internacional | economía | deportes |
| Cultura | Sociedad | Ciencia | Salud |
| ------- | -------- | ------- | ----- |
| cultura | sociedad | ciencia | salud |
| Tecnología | Comunicados | Estar donde estés |
| ---------- | ----------- | ----------------- |
| tecnología | comunicados | estar-donde-estes |
| Andalucía | Aragón | Cantabria | Castilla-La Mancha |
| --------- | ------ | --------- | ------------------ |
| andalucia | aragon | cantabria | castilla-lamancha |
| Castilla y León | Cataluña | Extremadura | Galicia |
| --------------- | --------- | ----------- | ------- |
| castilla-y-leon | catalunya | extremadura | galicia |
| Islas Canarias | Islas Baleares | Madrid | País Vasco |
| -------------- | -------------- | ------ | ---------- |
| islas-canarias | illes-balears | madrid | euskadi |
| La Rioja | C. Valenciana | Navarra | Asturias |
| -------- | -------------------- | ------- | -------- |
| la-rioja | comunitat-valenciana | navarra | asturias |
| Murcia | Ceuta y Melilla |
| ------ | --------------- |
| murcia | ceuta-y-melilla |`
};
async function handler(ctx) {
const { category = "" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 10;
const currentUrl = `https://www.europapress.es${category ? `/${category}` : ""}`;
const $ = load(await rofetch(currentUrl, { responseType: "text" }));
const items = await pMap($(".articulo-titulo, .c-item__title, .home-articulo-titulo").find("a").toArray().slice(0, limit).map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: $item.attr("href")
};
}), (item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link, { responseType: "text" }));
return {
...item,
description: (content(".full644").html() ?? "") + (content(".NormalTextoNoticia").html() ?? ""),
pubDate: parseDate(content("meta[name=\"date\"]").attr("content").replace(" ", ""))
};
}), { concurrency: 2 });
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };