rsshub
Version:
Make RSS Great Again!
179 lines (177 loc) • 8.04 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { t as timezone } from "./timezone-BBvDwS_3.mjs";
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
import { raw } from "hono/html";
//#region lib/routes/joins/chinese.tsx
const handler = async (ctx) => {
const { category = "" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 20;
const rootUrl = "https://chinese.joins.com";
const currentUrl = new URL(`news/articleList.html?view_type=s${category ? `&sc_section_code=${category}` : ""}`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const language = $("html").prop("lang");
let items = $("section.article-list-content div.table-row").slice(0, limit).toArray().map((item) => {
const $item = $(item);
return {
title: $item.find("strong").text(),
pubDate: timezone(parseDate($item.find("div.list-dated").text().split(/\|/).pop()), 8),
link: new URL($item.find("a.links").prop("href"), rootUrl).href,
author: $item.find("div.list-dated").text().split(/\|/, 1)[0],
language
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const $$ = load(detailResponse);
$$("a.articles").remove();
$$("div.view-copyright, div.ad-template, div.view-editors, div.tag-group").remove();
const title = $$("div.article-head-title, div.viewer-titles").text();
const description = renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [$$("div.photo-box").length === 0 ? null : $$("div.photo-box").toArray().map((i) => {
const src = $$(i).find("img").prop("src");
return src ? /* @__PURE__ */ jsx("figure", { children: /* @__PURE__ */ jsx("img", { src }) }) : null;
}), $$("div#article-view-content-div").html() ? raw($$("div#article-view-content-div").html()) : null] }));
const image = $$("meta[property=\"og:image\"]").prop("content");
item.title = title;
item.description = description;
item.pubDate = parseDate($$("meta[property=\"article:published_time\"]").prop("content"));
item.category = $$("meta[name=\"keywords\"]").prop("content")?.split(/,/) ?? $$("meta[name=\"news_keywords\"]").prop("content")?.split(/,/) ?? [];
item.author = $$("meta[property=\"og:article:author\"]").prop("content");
item.content = {
html: description,
text: $$("div#article-view-content-div").text()
};
item.image = image;
item.banner = image;
item.language = language;
return item;
})));
const image = new URL($("div.user-logo img").prop("src"), rootUrl).href;
return {
title: `${$(`a[data-code="${category}"]`)?.text() || $("ul#user-menu a").first().text()} - ${$("title").text()}`,
description: $("meta[property=\"og:description\"]").prop("content"),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: $("meta[property=\"og:site_name\"]").prop("content"),
language
};
};
const route = {
path: "/chinese/:category?",
name: "中央日报中文版",
url: "chinese.joins.com",
maintainers: ["nczitzk"],
handler,
example: "/joins/chinese",
parameters: { category: "分类,默认为空,可在对应分类页 URL 中找到 `sc_section_code`" },
description: `::: tip
若订阅 [财经](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N1),网址为 \`https://chinese.joins.com/news/articleList.html?sc_section_code=S1N1\`。截取 \`sc_section_code\` 的值作为参数填入,此时路由为 [\`/joins/chinese/S1N1\`](https://rsshub.app/joins/chinese/S1N1)。
:::
| 分类 | \`sc_section_code\` |
| ------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| [财经](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N1) | [S1N1](https://rsshub.app/joins/chinese/S1N1) |
| [国际](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N2) | [S1N2](https://rsshub.app/joins/chinese/S1N2) |
| [北韩](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N3) | [S1N3](https://rsshub.app/joins/chinese/S1N3) |
| [政治・社会](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N4) | [S1N4](https://rsshub.app/joins/chinese/S1N4) |
| [中国观察](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N5) | [S1N5](https://rsshub.app/joins/chinese/S1N5) |
| [社论](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N26) | [S1N26](https://rsshub.app/joins/chinese/S1N26) |
| [专栏・观点](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N11) | [S1N11](https://rsshub.app/joins/chinese/S1N11) |
| [军事・科技](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N6) | [S1N6](https://rsshub.app/joins/chinese/S1N6) |
| [娱乐体育](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N7) | [S1N7](https://rsshub.app/joins/chinese/S1N7) |
| [教育](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N8) | [S1N8](https://rsshub.app/joins/chinese/S1N8) |
| [旅游美食](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N9) | [S1N9](https://rsshub.app/joins/chinese/S1N9) |
| [时尚](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N10) | [S1N10](https://rsshub.app/joins/chinese/S1N10) |
| [图集](https://chinese.joins.com/news/articleList.html?sc_section_code=S1N12\\&view_type=tm) | [S1N12](https://rsshub.app/joins/chinese/S1N12) |`,
categories: ["traditional-media"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [
{
source: ["chinese.joins.com/news/articleList.html"],
target: (url) => {
const category = url.searchParams.get("sc_section_code");
return `/joins/chinese${category ? `/${category}` : ""}`;
}
},
{
title: "财经",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N1"
},
{
title: "国际",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N2"
},
{
title: "北韩",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N3"
},
{
title: "政治·社会",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N4"
},
{
title: "中国观察",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N5"
},
{
title: "社论",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N26"
},
{
title: "专栏·观点",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N11"
},
{
title: "军事·科技",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N6"
},
{
title: "娱乐体育",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N7"
},
{
title: "教育",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N8"
},
{
title: "旅游美食",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N9"
},
{
title: "时尚",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N10"
},
{
title: "图集",
source: ["chinese.joins.com/news/articleList.html"],
target: "/chinese/S1N12"
}
]
};
//#endregion
export { handler, route };