rsshub
Version:
Make RSS Great Again!
41 lines (40 loc) • 1.5 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as timezone } from "./timezone-DE--ze1V.mjs";
import { load } from "cheerio";
//#region lib/routes/gamer/utils.ts
const fetchItem = (item) => cache_default.tryGet(item.link, async () => {
const $ = load(await rofetch(item.link));
const content = $("#article_content, .card");
content.find(".form__buttonbar").remove();
content.find("a[href^=\"https://ref.gamer.com.tw/redir.php\"]").each((_, a) => {
const url = new URL($(a).attr("href")).searchParams.get("url");
if (url) $(a).attr("href", url);
});
content.prepend($("#div_illustration img").toArray().map((img) => `<img src="${$(img).parent().attr("data-src")}">`).join(""));
return {
...item,
description: content.html()
};
});
const ProcessFeed = async (url) => {
const $ = load(await rofetch(url));
const title = $("title").text();
const list = $(".platform-info-box").toArray().map((item) => {
const $item = $(item);
const a = $item.find(".HOME-mainwrap1 h1 > a");
return {
title: a.text(),
link: a.attr("href"),
author: $item.find(".mainbox-author").text(),
pubDate: timezone(parseDate($item.find(".caption-text").not(".height-limit").text().split("|", 2)[1]), 8)
};
});
return {
title,
items: await Promise.all(list.map((item) => fetchItem(item)))
};
};
//#endregion
export { fetchItem as n, ProcessFeed as t };