rsshub
Version:
Make RSS Great Again!
62 lines (61 loc) • 2.13 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 { load } from "cheerio";
//#region lib/routes/yxrb/home.ts
const baseUrl = "http://news.yxrb.net";
const route = {
path: "/:category?",
categories: ["game"],
example: "/yxrb/info",
parameters: { category: "分类,见下表,预设为 `info`" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["news.yxrb.net/:category", "news.yxrb.net/"],
target: "/:category"
}],
name: "分类",
maintainers: ["TonyRL"],
handler,
description: `| 资讯 | 访谈 | 服务 | 游理游据 |
| ---- | ------- | ------- | -------- |
| info | talking | service | comments |`
};
async function handler(ctx) {
const { category = "info" } = ctx.req.param();
const link = `${baseUrl}/${category}/`;
const $ = load((await got_default(link)).data);
const list = $(".channel-news .item").toArray().map((item) => {
const $item = $(item);
return {
title: $item.find(".title a").attr("title"),
link: `${baseUrl}${$item.find(".title a").attr("href")}`,
author: $item.find(".author a").text().split("作者 : ", 2)[1]
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const $ = load((await got_default(item.link)).data);
item.author ??= $(".author-info .name a").text().split("作者 : ", 2)[1];
item.pubDate = timezone(parseDate($(".publish-time").first().contents().filter((_, e) => e.nodeType === 3).text().trim(), "YYYY-MM-DD HH:mm:ss"), 8);
item.description = $("article").html();
item.category = $(".tags a").toArray().map((item) => $(item).text());
return item;
})));
return {
title: $("head title").text(),
description: $("head meta[name=description]").attr("content"),
link,
image: $(".channel-img img").attr("src"),
item: items
};
}
//#endregion
export { route };