UNPKG

rsshub

Version:
56 lines (54 loc) 2.45 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/dcfever/utils.ts init_esm_shims(); const baseUrl = "https://www.dcfever.com"; const parseItem = (item) => cache_default.tryGet(item.link, async () => { const $ = load(await ofetch_default(item.link)); const content = $("div[itemprop=\"articleBody\"], .column_article_content_html"); const pageLinks = $(".article_multi_page a").not(".selected").toArray().map((i) => ({ link: new URL($(i).attr("href"), item.link).href })); if (pageLinks.length) { const pages = await Promise.all(pageLinks.map(async (pageLink) => { return load(await ofetch_default(pageLink.link))("div[itemprop=\"articleBody\"]").html(); })); content.append(pages); } content.find("img").each((_, e) => { if (e.attribs.src?.includes("?")) e.attribs.src = e.attribs.src.split("?")[0]; }); content.find("p a").each((_, e) => { e = $(e); if (e.text().startsWith("下一頁為")) e.remove(); }); content.find("iframe").each((_, e) => { e = $(e); if (e.attr("src").startsWith("https://www.facebook.com/plugins/like.php")) e.remove(); }); item.description = content.html(); item.pubDate = parseDate($("meta[property=\"article:published_time\"]").attr("content")); return item; }); const parseTradeItem = (item) => cache_default.tryGet(item.link, async () => { const $ = load(await ofetch_default(item.link)); const $photo = load($("#trading_item_section .description").contents().filter((_, e) => e.type === "comment").toArray().map((e) => e.data).join(""), null, false); $photo(".selector_text").remove(); $photo(".selector_image_div").each((_, div) => { delete div.attribs.onclick; }); $photo(".desktop_photo_selector img").each((_, img) => { if (img.attribs.src.endsWith("_sqt.jpg")) img.attribs.src = img.attribs.src.replace("_sqt.jpg", ".jpg"); }); item.description = art(path.join(__dirname, "templates/trading-949c0be3.art"), { info: $(".info_col"), description: $(".description_text").html(), photo: $photo(".desktop_photo_selector").html() }); return item; }); //#endregion export { parseItem as n, parseTradeItem as r, baseUrl as t };