rsshub
Version:
Make RSS Great Again!
61 lines (59 loc) • 2.16 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 { load } from "cheerio";
//#region lib/routes/sankei/news.ts
const route = {
path: "/news/:category",
categories: ["traditional-media"],
example: "/sankei/news/flash",
parameters: { category: "Category name (as it will appear in URLs). For example, for \"Breaking News\" https://www.sankei.com/flash/, the category name would be \"flash\"." },
radar: [{
source: ["www.sankei.com/:category"],
target: "/news/:category"
}],
name: "News",
maintainers: ["yuikisaito"],
handler
};
async function handler(ctx) {
const baseUrl = "https://www.sankei.com";
const { category } = ctx.req.param();
const url = `${baseUrl}/${category}/`;
const $ = load((await got_default(url)).body);
const categoryName = $("header.story-card-header:first-of-type > h1").text();
const listSelector = $("div.story-card-feed.grid.hide_on_mobile > div > article");
const items = await Promise.all(listSelector.toArray().map((el) => {
const item = $(el);
item.find("p a").remove();
const title = item.find("div.story-card-flex > h2.headline > a").text();
const link = baseUrl + (item.find("div.story-card-flex > h2.headline > a").attr("href") || "");
const pubDate = parseDate(item.find("div.story-card-flex > div > time").attr("datetime") || "");
return cache_default.tryGet(link, async () => {
const $$1 = load((await got_default(link)).body);
$$1(".inline-gptAd, .figure_image_sizer").remove();
return {
title,
link,
pubDate,
description: $$1("div.article-body").html() || ""
};
});
}));
return {
title: "産経ニュース - " + categoryName,
description: $("meta[name=\"description\"]").attr("content"),
link: url,
image: $("meta[property=\"og:image\"]").attr("content"),
language: "ja",
item: items
};
}
//#endregion
export { route };