UNPKG

rsshub

Version:
57 lines (56 loc) 1.87 kB
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 { load } 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 $ = load(res); const list = $(".news_list ul li").toArray().map((item) => { const $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 } = await got_default(item.link); const $ = load(res); if (item.link.startsWith("https://tonglinv.pixnet.net/")) item.description = $(".article-content-inner").html(); else if (/^https?:\/\/blog\.xuite\.net\//.test(item.link)) item.description = $("#content_all").html(); else if (/TNews_View\.aspx/.test(item.link)) item.description = $("#ContentPlaceHolder1_TNewsContent").html(); else item.description = ""; return item; }))); return { title: $(".entry_title .n1").text(), link, item: items }; } //#endregion export { route };