rsshub
Version:
Make RSS Great Again!
94 lines (92 loc) • 3.57 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.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/visionias/utils.ts
init_esm_shims();
const baseUrl = "https://visionias.in";
async function extractNews(item, selector) {
if (item.link === "") return item;
return await cache_default.tryGet(item.link, async () => {
const $$ = load(await ofetch_default(item.link || ""));
const postedDate = String($$("meta[property=\"article:published_time\"]").attr("content"));
const updatedDate = String($$("meta[property=\"article:modified_time\"]").attr("content"));
const tags = $$("meta[property=\"article:tag\"]").toArray().map((tag) => $$(tag).attr("content"));
const content = $$(selector);
const heading = content.find("div.space-y-4 > h1").text();
const mainGroup = content.find("div.flex > div.w-full");
const shortArticles = mainGroup.find("[x-data^=\"{isShortArticleOpen\"]");
const sections = mainGroup.find("[x-data^=\"{isSectionOpen\"]");
if (shortArticles.length !== 0) return shortArticles.toArray().map((element) => {
const mainDiv = $$(element);
const title = mainDiv.find("a > div > h2").text().trim();
const id = mainDiv.find("a").attr("href");
const htmlContent = extractArticle(mainDiv.html());
const innerTags = mainDiv.find("ul > li:contains(\"Tags :\")")?.nextAll("li").toArray().map((tag) => $$(tag).text());
const description = art(path.join(__dirname, "templates/description-962ff3f8.art"), {
heading: title,
articleContent: htmlContent
});
return {
title: `${title} | ${heading}`,
pubDate: parseDate(postedDate),
category: innerTags,
description,
link: `${item.link}${id}`,
author: "Vision IAS"
};
});
else if (sections.length === 0) {
const htmlContent = extractArticle(mainGroup.html());
const description = art(path.join(__dirname, "templates/description-962ff3f8.art"), {
heading,
articleContent: htmlContent
});
return {
title: item.title,
pubDate: parseDate(postedDate),
category: tags,
description,
link: item.link,
updated: updatedDate ? parseDate(updatedDate) : null,
author: "Vision IAS"
};
} else {
const items = sections.toArray().map((element) => {
const mainDiv = $$(element);
const title = mainDiv.find("a > div > h2").text().trim();
const htmlContent = extractArticle(mainDiv.html(), "div.ck-content");
return { description: art(path.join(__dirname, "templates/description-sub-290c84a9.art"), {
heading: title,
articleContent: htmlContent
}) };
});
const description = art(path.join(__dirname, "templates/description-962ff3f8.art"), {
heading,
subItems: items
});
return {
title: heading,
pubDate: parseDate(postedDate),
category: tags,
description,
link: item.link,
updated: updatedDate ? parseDate(updatedDate) : null,
author: "Vision IAS"
};
}
});
}
function extractArticle(articleDiv, selectorString = "div.ck-content") {
const $ = load(articleDiv, null, false);
const articleContent = $(articleDiv).find(String(selectorString));
articleContent.find("figure").each((_, element) => {
$(element).css("width", "");
});
return articleContent.html();
}
//#endregion
export { extractNews as n, baseUrl as t };