rsshub
Version:
Make RSS Great Again!
82 lines (81 loc) • 2.28 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as timezone } from "./timezone-DE--ze1V.mjs";
import { load } from "cheerio";
const route = {
path: "/:category?",
categories: ["new-media"],
example: "/kuai/stock_us",
parameters: { category: {
description: "栏目,留空为首页",
options: Object.entries({
astrology: "星相",
canada: "加国",
children: "育儿",
china: "大陆",
chinese: "华人",
edu: "教育",
ent: "娱乐",
fashion: "时尚",
finance: "财经",
food: "美食",
funny: "搞笑",
health: "养生",
history: "历史",
hk_macau: "港澳",
immigration: "移民",
in: "国际",
it: "科技",
love: "情感",
mil: "军事",
misc: "杂闻",
pet: "宠物",
photo: "摄影",
politics: "政坛",
sport: "体育",
stock_us: "美股",
taiwan: "台湾",
travel: "旅游",
usa: "美国"
}).map(([value, label]) => ({
value,
label
}))
} },
radar: [{
source: ["www.kuai.media/news/:category/"],
target: "/:category"
}],
name: "首页更新 / 具体栏目更新",
maintainers: ["salviox"],
handler,
url: "www.kuai.media"
};
async function handler(ctx) {
const { category } = ctx.req.param();
const baseUrl = "https://www.kuai.media";
const link = category ? `${baseUrl}/news/${category}/` : baseUrl;
const $ = load(await rofetch(link));
const list = $(".data_row").slice(0, ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 40).toArray().map((item) => {
const a = $(item).find(".news_title h3 a");
return {
title: a.text().trim(),
link: new URL(a.attr("href"), baseUrl).href
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
content(".s .more").remove();
item.pubDate = timezone(parseDate(content(".xg1.hm").contents().first().text().trim(), "YYYY-M-D HH:mm"), 8);
item.description = (content(".s a").html()?.trim() ?? "") + (content(".video").html() ?? "");
return item;
})));
return {
title: $("head title").text(),
link,
item: items
};
}
//#endregion
export { route };