rsshub
Version:
Make RSS Great Again!
78 lines (76 loc) • 2.69 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import { t as logger_default } from "./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 rss_parser_default } from "./rss-parser-Dtop7M8f.mjs";
import { load } from "cheerio";
//#region lib/routes/cointelegraph/index.ts
const route = {
path: "/",
categories: ["finance"],
example: "/cointelegraph",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "News",
maintainers: ["pseudoyu"],
handler,
radar: [{
source: ["cointelegraph.com/"],
target: "/"
}],
description: "Get latest news from Cointelegraph with full text."
};
async function handler() {
const feed = await rss_parser_default.parseURL("https://cointelegraph.com/rss");
const validItems = (await Promise.all(feed.items.filter((item) => item.link && /\/news|\/explained|\/innovation-circle/.test(item.link)).map((item) => ({
...item,
link: item.link?.split("?")[0]
})).map((item) => cache_default.tryGet(item.link, async () => {
const link = item.link;
const fullText = await extractFullText(link);
if (!fullText) logger_default.warn(`Failed to extract content from ${link}`);
return {
title: item.title || "Untitled",
description: fullText || item.content,
pubDate: item.pubDate ? parseDate(item.pubDate) : void 0,
link,
author: item.creator || "CoinTelegraph",
category: item.categories?.map((c) => c.trim()) || [],
image: item.enclosure?.url
};
})))).filter((item) => item !== null);
return {
title: feed.title || "CoinTelegraph News",
link: feed.link || "https://cointelegraph.com",
description: feed.description || "Latest news from CoinTelegraph",
language: feed.language || "en",
item: validItems
};
}
async function extractFullText(url) {
try {
const $ = load(await ofetch_default(url));
const nuxtData = $("script:contains(\"window.__NUXT__\")").text();
const fullText = JSON.parse(nuxtData.match(/\.fullText=(".*?");/)?.[1] || "{}");
const cover = $(".post-cover__image");
cover.find("source").remove();
cover.find("img").removeAttr("srcset");
cover.find("img").attr("src", cover.find("img").attr("src")?.match(/(https:\/\/s3\.cointelegraph\.com\/.+)/)?.[1] || "");
return cover.html() + fullText || null;
} catch (error) {
logger_default.error(`Error fetching article content: ${error}`);
return null;
}
}
//#endregion
export { route };