rsshub
Version:
Make RSS Great Again!
58 lines (56 loc) • 2.22 kB
JavaScript
import { t as logger_default } from "./logger-Czu8UMNd.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { load } from "cheerio";
//#region lib/routes/dnaindia/common.ts
async function handler(ctx) {
const { category, topic } = ctx.req.param();
const baseUrl = "https://www.dnaindia.com";
let route;
if (category) route = `/${category}`;
else if (topic) route = `/topic/${topic}`;
else logger_default.error("Invalid URL");
const link = `${baseUrl}${route}`;
const { data: response } = await got_default(link);
const $ = load(response);
const listItems = $("div.list-news").toArray().map((item) => {
item = $(item);
const a = item.find("div.explainer-subtext a");
return {
title: a.text(),
link: `${baseUrl}${a.attr("href")}`
};
});
return {
title: "DNA India",
link,
item: await Promise.all(listItems.map((item) => cache_default.tryGet(item.link, async () => {
const { data: response$1 } = await got_default(item.link);
const $$1 = load(response$1);
const itunes_item_image = $$1("div.article-img img").attr("src");
const category$1 = $$1("div.tags ul li").toArray().map((item$1) => $$1(item$1).find("a").text());
const dateMatch = $$1("p.dna-update").text().match(/Updated\s*:\s*([\w\s,:\d]+?)(?:\s*\||$)/);
let time = dateMatch ? dateMatch[1].trim() : "";
time = time.replace(/\s+IST$/, "");
const pubDate = timezone(parseDate(time), 5.5);
const author = $$1("meta[name=\"author\"]").attr("content") || "DNA Web Team";
const description = $$1("div.article-description").clone().children("div").remove().end().toArray().map((element) => $$1(element).html()).join("");
return {
...item,
itunes_item_image,
category: category$1,
pubDate,
author,
description
};
}))),
description: "Latest News on dnaIndia.com",
logo: "https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico",
icon: "https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico",
language: "en-us"
};
}
//#endregion
export { handler as t };