rsshub
Version:
Make RSS Great Again!
54 lines (52 loc) • 1.99 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.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";
//#region lib/routes/yicai/utils.ts
init_esm_shims();
const rootUrl = "https://www.yicai.com";
const ProcessItems = async (apiUrl, tryGet) => {
const items = (await got_default({
method: "get",
url: apiUrl
})).data.map((item) => ({
title: item.NewsTitle,
link: item.url.startsWith("http") ? item.url : `${rootUrl}${item.AppID === 0 ? `/vip` : ""}${item.url}`,
author: item.NewsAuthor || item.NewsSource || item.CreaterName,
pubDate: timezone(parseDate(item.CreateDate), 8),
category: [item.ChannelName],
description: art(path.join(__dirname, "templates/description-55895928.art"), {
image: {
src: item.originPic,
alt: item.NewsTitle
},
video: {
src: item.VideoUrl,
type: item.VideoUrl?.split(/\./).pop() ?? void 0
},
intro: item.NewsNotes
})
}));
return Promise.all(fetchFullArticles(items, tryGet));
};
function fetchFullArticles(items, tryGet) {
return items.map((item) => tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
if (!item.pubDate) {
const dataScript = content("script[src='/js/alert.min.js']").next().text() || content("title").next().text();
item.pubDate = parseDate(`${new Map(JSON.parse(dataScript.match(/_pb = (\[.*?]);/)[1].replaceAll("'", "\""))).get("actime")}:00`);
}
content("h1").remove();
content(".u-btn6, .m-smallshare, .topic-hot").remove();
item.description = (item.description ?? "") + (content(".multiText, #multi-text, .txt").html() ?? "");
return item;
}));
}
//#endregion
export { fetchFullArticles as n, rootUrl as r, ProcessItems as t };