UNPKG

rsshub

Version:
90 lines (87 loc) 3.32 kB
import { n as init_esm_shims, t as __dirname } from "./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 "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; import iconv from "iconv-lite"; //#region lib/routes/baidu/tieba/search.ts init_esm_shims(); const route = { path: "/tieba/search/:qw/:routeParams?", categories: ["bbs"], example: "/baidu/tieba/search/neuro", parameters: { qw: "搜索关键词", routeParams: "额外参数;请参阅以下说明和表格" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "贴吧搜索", maintainers: ["JimenezLi"], handler, description: `| 键 | 含义 | 接受的值 | 默认值 | | ------------ | ---------------------------------------------------------- | ------------- | ------ | | kw | 在名为 kw 的贴吧中搜索 | 任意名称 / 无 | 无 | | only_thread | 只看主题帖,默认为 0 关闭 | 0/1 | 0 | | rn | 返回条目的数量 | 1-20 | 20 | | sm | 排序方式,0 为按时间顺序,1 为按时间倒序,2 为按相关性顺序 | 0/1/2 | 1 | 用例:\`/baidu/tieba/search/neuro/kw=neurosama&only_thread=1&sm=2\`` }; async function handler(ctx) { const qw = ctx.req.param("qw"); const query = new URLSearchParams(ctx.req.param("routeParams")); query.set("ie", "utf-8"); query.set("qw", qw); query.set("rn", query.get("rn") || "20"); const link = `https://tieba.baidu.com/f/search/res?${query.toString()}`; const response = await got_default.get(link, { headers: { Referer: "https://tieba.baidu.com" }, responseType: "buffer" }); const $ = load(iconv.decode(response.data, "gbk")); const resultList = $("div.s_post"); return { title: `${qw} - ${query.get("kw") || "百度贴"}吧搜索`, link, item: resultList.toArray().map((element) => { const item = $(element); const titleItem = item.find(".p_title a"); const title = titleItem.text().trim(); const link$1 = titleItem.attr("href"); const time = item.find(".p_date").text().trim(); const details = item.find(".p_content").text().trim(); const medias = item.find(".p_mediaCont img").toArray().map((element$1) => { return `<img src="${$(element$1).attr("original")}">`; }).join(""); const tieba = item.find("a.p_forum").text().trim(); const author = item.find("a").last().text().trim(); return { title, description: art(path.join(__dirname, "templates/tieba_search-a766b6b5.art"), { details, medias, tieba, author }), author, pubDate: timezone(parseDate(time, "YYYY-MM-DD HH:mm"), 8), link: link$1 }; }) }; } //#endregion export { route };