UNPKG

rsshub

Version:
64 lines (62 loc) 2.09 kB
import "./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 got_default } from "./got-KxxWdaxq.mjs"; import * as cheerio from "cheerio"; //#region lib/routes/tongli/news.ts const route = { path: "/news/:type", categories: ["reading"], example: "/tongli/news/6", parameters: { type: "分類,可以在“新聞”鏈接中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "新聞", maintainers: ["CokeMine"], handler }; async function handler(ctx) { const { type } = ctx.req.param(); const baseURL = "https://www.tongli.com.tw/"; const { data: res, url: link } = await got_default(`${baseURL}TNews_List.aspx`, { searchParams: { Type: type, Page: 1 } }); const $ = cheerio.load(res); const list = $(".news_list ul li").toArray().map((item) => { item = $(item); const a = item.find(".title a"); return { title: a.text(), link: a.attr("href").startsWith("http") ? a.attr("href") : baseURL + a.attr("href"), pubDate: parseDate(item.find(".date").text(), "YYYY.MM.DD") }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const { data: res$1 } = await got_default(item.link); const $$1 = cheerio.load(res$1); if (/^https:\/\/tonglinv\.pixnet\.net/.test(item.link)) item.description = $$1(".article-content-inner").html(); else if (/^https?:\/\/blog\.xuite\.net\//.test(item.link)) item.description = $$1("#content_all").html(); else if (/TNews_View\.aspx/.test(item.link)) item.description = $$1("#ContentPlaceHolder1_TNewsContent").html(); else item.description = ""; return item; }))); return { title: $(".entry_title .n1").text(), link, item: items }; } //#endregion export { route };