rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 2.28 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import "./ofetch-DKl_Ma9g.mjs";
import { t as parseDate } from "./parse-date-r5WDWHno.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.mjs";
import "./helpers-Bo4JQYdN.mjs";
import { r as getSubPath } from "./common-utils-Cz5bFBus.mjs";
import { t as got_default } from "./got-CO-ndVl2.mjs";
import { t as timezone } from "./timezone-CA9Huotp.mjs";
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
//#region lib/routes/sinchew/index.tsx
const route = {
path: "*",
radar: [{
source: ["sinchew.com.my/"],
target: ""
}],
name: "Unknown",
maintainers: [],
handler,
url: "sinchew.com.my/"
};
async function handler(ctx) {
const rootUrl = "https://www.sinchew.com.my";
const currentUrl = `${rootUrl}${getSubPath(ctx) === "/" ? "" : getSubPath(ctx)}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $(".title .internalLink").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20).toArray().map((item) => {
item = $(item);
const link = item.attr("href");
return {
title: item.attr("data-title"),
link: link.startsWith("http") ? link : `${rootUrl}${link}`,
pubDate: timezone(parseDate(item.text()), 8)
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
content(".ads-frame, .read-more-msg").remove();
content("figure").each(function() {
content(this).replaceWith(renderToString(/* @__PURE__ */ jsxs("figure", { children: [/* @__PURE__ */ jsx("img", { src: content(this).find("img").attr("src") }), /* @__PURE__ */ jsx("figcaption", { children: content(this).find("figcaption").text() })] })));
});
item.description = content(".article-page-content").html();
item.pubDate = timezone(parseDate(content("meta[property=\"article:published_time\"]").attr("content")), 8);
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };