rsshub
Version:
Make RSS Great Again!
57 lines (55 loc) • 1.73 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 "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import "./timezone-D8cuwzTY.mjs";
import { n as parseArticle } from "./utils-CLavV0oP.mjs";
import { load } from "cheerio";
//#region lib/routes/sina/sports.ts
const route = {
path: "/sports/:type?",
name: "新浪体育",
categories: ["new-media"],
example: "/sports",
parameters: { type: "类别" },
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const type = ctx.req.param("type");
let currentUrl = `https://sports.sina.com.cn/others/${type}.shtml`;
let query = "ul.list2 li a";
if (type === "ufc") {
currentUrl = "http://roll.sports.sina.com.cn/s_ufc_all/index.shtml";
query = "#d_list ul li span a";
} else if (type === "winter" || type === "horse") {
currentUrl = `https://sports.sina.com.cn/${type}/`;
query = "[class^=news-list] .list li a";
}
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
const list = $(query).toArray().map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr("href").replace("http://", "https://")
};
});
const items = await Promise.all(list.map((item) => parseArticle(item, cache_default.tryGet)));
return {
title: `${$("title").text().split("_")[0]} - 新浪体育`,
description: $("meta[name=\"description\"]").attr("content"),
link: currentUrl,
item: items
};
}
//#endregion
export { route };