rsshub
Version:
Make RSS Great Again!
91 lines (89 loc) • 3.96 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/nikkei/news.ts
init_esm_shims();
const route = {
path: "/news/:category/:article_type?",
categories: ["traditional-media"],
example: "/nikkei/news/news",
parameters: {
category: "Category, see table below",
article_type: "Only includes free articles, set `free` to enable, disabled by default"
},
radar: [{
source: ["www.nikkei.com/:category/archive", "www.nikkei.com/:category"],
target: "/:category"
}],
name: "News",
maintainers: ["Arracc", "ladeng07"],
handler,
description: `| 総合 | オピニオン | 経済 | 政治 | 金融 | マーケット | ビジネス | マネーのまなび | テック | 国際 | スポーツ | 社会・調査 | 地域 | 文化 | ライフスタイル |
| ---- | ---------- | ------- | -------- | --------- | ---------- | -------- | -------------- | ---------- | ------------- | -------- | ---------- | ----- | ------- | -------------- |
| news | opinion | economy | politics | financial | business | 不支持 | 不支持 | technology | international | sports | society | local | culture | lifestyle |`
};
async function handler(ctx) {
const baseUrl = "https://www.nikkei.com";
const { category, article_type = "paid" } = ctx.req.param();
let url = "";
url = category === "news" ? `${baseUrl}/news/category/` : `${baseUrl}/${category}/archive/`;
const data = (await got_default(url)).data;
const $ = load(data);
let categoryName = "";
const listSelector = $("[class^=\"container_\"] [class^=\"default_\"]:has(article)");
const paidSelector = "img[class^=\"icon_\"]";
let list = listSelector.toArray().map((item) => {
item = $(item);
item.find("p a").remove();
return {
title: item.find("[class^=\"titleLink_\"]").text(),
link: `${baseUrl}${item.find("[class^=\"title_\"] a").attr("href")}`,
image: item.find("[class^=\"image_\"] img").removeAttr("style").removeAttr("width").removeAttr("height").parent().html(),
category: item.find("[class^=\"topicItem_\"] a").toArray().map((item$1) => $(item$1).text()),
paywall: !!item.find(paidSelector).length
};
});
if (category === "news") {
categoryName = "総合";
list = [...list, ...$("div#CONTENTS_MAIN .m-miM32_itemTitle").toArray().map((item) => {
item = $(item);
const a = item.find("a").first();
return {
title: a.text(),
link: `${baseUrl}${a.attr("href")}`,
category: item.find(".m-miM32_itemkeyword a").toArray().map((item$1) => $(item$1).text()),
paywall: !!item.find(paidSelector).length
};
})];
} else categoryName = $("h1.l-miH11_title").text().trim();
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const { data: response } = await got_default(item.link);
const $$1 = load(response);
$$1(".notFloated_n1oadkwi").remove();
item.pubDate = parseDate($$1("meta[property=\"article:published_time\"]").attr("content"));
item.description = art(path.join(__dirname, "templates/news-b626ffdc.art"), {
item,
description: $$1("section[class^=container_]").html()
});
return item;
})));
return {
title: "日本経済新聞 - " + categoryName,
description: $("meta[name=\"description\"]").attr("content"),
link: url,
image: $("meta[property=\"og:image\"]").attr("content"),
language: "ja",
item: article_type === "free" ? items.filter((item) => !item.paywall) : items
};
}
//#endregion
export { route };