UNPKG

rsshub

Version:
79 lines (77 loc) 2.7 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/dgtle/util.ts init_esm_shims(); const baseUrl = "https://www.dgtle.com"; const ProcessItems = async (limit, dataList) => { let items = []; items = dataList.slice(0, limit).map((item) => { const title = item.title || item.content; const image = item.cover; const description = art(path.join(__dirname, "templates/description-36fefaf3.art"), { images: image ? [{ src: image, alt: title }] : void 0, intro: item.content }); const pubDate = item.created_at; const linkUrl = `${item.live_status === void 0 ? item.category_name ? "article" : "news" : "live"}-${item.id}-1.html`; const categories = [...new Set([item.column, item.category_name].filter(Boolean))]; const authors = [{ name: item.user?.username ?? item.user_name, url: new URL(`user?uid=${item.user_id}`, baseUrl).href, avatar: item.user?.avatar_path ?? item.avatar_path }]; const guid = `dgtle-${item.id}`; const updated = pubDate; return { title, description, pubDate: pubDate ? parseDate(pubDate, "X") : void 0, link: new URL(linkUrl, baseUrl).href, category: categories, author: authors, guid, id: guid, content: { html: description, text: description }, image, banner: image, updated: updated ? parseDate(updated, "X") : void 0, live_status: item.live_status }; }); items = await Promise.all(items.map((item) => { if (item.live_status !== void 0 || !item.link) { delete item.live_status; return item; } delete item.live_status; return cache_default.tryGet(item.link, async () => { const $$ = load(await ofetch_default(item.link)); $$("div.logo").remove(); $$("p.tip").remove(); $$("p.dgtle").remove(); $$("figure").each((_, el) => { const $$el = $$(el); $$el.replaceWith(art(path.join(__dirname, "templates/description-36fefaf3.art"), { images: [{ src: $$el.find("img").attr("data-original")?.replace(/_\d+_\d+_w/, "") }] })); }); const processedItem = { description: art(path.join(__dirname, "templates/description-36fefaf3.art"), { description: $$("div.whale_news_detail-daily-content, div#articleContent, div.forum-viewthread-article-box").html() }) }; return { ...item, ...processedItem }; }); })); return items; }; //#endregion export { baseUrl as n, ProcessItems as t };