UNPKG

rsshub

Version:
70 lines (68 loc) 2.38 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/sogou/search.ts init_esm_shims(); const renderDescription = (description, images) => art(path.join(__dirname, "templates/description-7ea94b3d.art"), { description, images }); const route = { path: "/search/:keyword", categories: ["other"], example: "/sogou/search/rss", parameters: { keyword: "搜索关键词" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "搜索", maintainers: ["CaoMeiYouRen"], handler }; async function handler(ctx) { const keyword = ctx.req.param("keyword"); const url = `https://www.sogou.com/web?query=${encodeURIComponent(keyword)}`; const key = `sogou-search:${url}`; const items = await cache_default.tryGet(key, async () => { const response = (await got_default(url)).data; const $ = load(response); return $("#main").find(".vrwrap").toArray().map((el) => { const element = $(el); const imgs = element.find("img").toArray().map((el2) => $(el2).attr("src")); const link = element.find("h3 a").first().attr("href"); const title = element.find("h3").first().text(); const description = element.find(".text-layout").first().text() || element.find(".space-txt").first().text() || element.find("[class^=\"translate\"]").first().text(); const author = element.find(".citeurl span").first().text() || ""; const pubDate = parseDate(element.find(".citeurl .cite-date").first().text().trim()); return { link, title, description: renderDescription(description, imgs), author, pubDate }; }).filter((e) => e?.link); }, config.cache.routeExpire, false); return { title: `${keyword} - 搜狗搜索`, description: `${keyword} - 搜狗搜索`, link: url, item: items }; } //#endregion export { route };