UNPKG

rsshub

Version:
34 lines (33 loc) 1.35 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { load } from "cheerio"; import iconv from "iconv-lite"; //#region lib/utils/common-config.ts function resolveValue(value, select) { return typeof value === "function" ? value(select) : value; } async function buildData(data) { const response = await rofetch.raw(data.url); const contentType = response.headers.get("content-type") || ""; let charset = "utf-8"; for (const attr of contentType.split(";")) if (attr.includes("charset=")) charset = (attr.split("=").pop() || "utf-8").toLowerCase(); const responseData = charset === "utf-8" ? response._data : iconv.decode(Buffer.from(await rofetch(data.url, { responseType: "arrayBuffer" })), charset); const $ = load(responseData); return { link: data.link, title: resolveValue(data.title, $), description: resolveValue(data.description, $), allowEmpty: data.allowEmpty || false, item: $(data.item.item).toArray().map((element) => { const select = (selector) => $(element).find(selector); return { title: resolveValue(data.item.title, select), description: resolveValue(data.item.description, select), pubDate: resolveValue(data.item.pubDate, select), link: resolveValue(data.item.link, select), guid: resolveValue(data.item.guid, select) }; }) }; } //#endregion export { buildData as t };