rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 2.33 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.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/koreaherald/index.ts
const route = {
path: "/:category{.+}?",
categories: ["traditional-media"],
example: "/koreaherald/National",
parameters: { category: "Category from the path of the URL of the corresponding site, `National` by default" },
features: {
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
requireConfig: false
},
name: "News",
maintainers: ["quiniapiezoelectricity"],
handler,
description: `
::: tip
For example, the category for the page https://www.koreaherald.com/Business and https://www.koreaherald.com/Business/Market would be \`/Business\` and \`/Business/Market\` respectively.
:::
`,
radar: [{
source: ["www.koreaherald.com/:category"],
target: "/:category"
}]
};
async function handler(ctx) {
const category = ctx.req.param("category") ?? "National";
const baseUrl = "https://www.koreaherald.com/";
const $ = load((await got_default(new URL(category, baseUrl).href)).data);
const title = $("ul.gnb").find("[class=\"on\"]").length > 0 ? $("ul.gnb").find("[class=\"on\"]").text() : $("div.nav_area > a.category").text();
const list = $("article.recent_news > ul.news_list > li").toArray().map((item) => new URL($(item).find("a").attr("href"), baseUrl).href);
const items = await Promise.all(list.map((url) => cache_default.tryGet(url, async () => {
const $$1 = load((await got_default(url)).data);
const metadata = JSON.parse($$1("[type=\"application/ld+json\"]").text());
return {
title: metadata.headline,
link: url,
pubDate: timezone(parseDate(metadata.datePublished), 9),
author: metadata.author.name,
description: $$1("article.article-body").html()
};
})));
return {
title: `The Korea Herald - ${title}`,
link: new URL(category, baseUrl).href,
item: items
};
}
//#endregion
export { route };