rsshub
Version:
Make RSS Great Again!
102 lines (100 loc) • 3.34 kB
JavaScript
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/dribbble/utils.ts
init_esm_shims();
const host = "https://dribbble.com";
async function loadContent(link) {
const $ = load(await ofetch_default(link));
const shotData = JSON.parse($("script").text().match(/shotData:\s({.+?}),\n/)?.[1] ?? "{}");
const shotMedia = $(".media-shot, .main-shot, .block-media-wrapper").toArray().map((element) => {
const object = $(element);
object.find("span.cropped-indicator, button").remove();
object.find("video").each((_, video) => {
video = $(video);
if (!video.attr("src") && video.data("src")) {
video.attr("src", video.data("src"));
video.removeAttr("data-src");
video.removeAttr("data-video-small");
video.removeAttr("data-video-medium");
video.removeAttr("data-video-large");
}
});
object.find("img").each((_, img) => {
img = $(img);
if (img.data("animated-url")) {
img.attr("src", img.data("animated-url"));
img.removeAttr("data-animated-url");
img.removeAttr("srcset");
}
if (!img.attr("src") && img.data("src")) {
img.attr("src", img.data("src").split("?")[0]);
img.removeAttr("data-src");
}
img.attr("src", img.attr("src").split("?")[0]);
img.removeAttr("srcset");
img.removeAttr("data-srcset");
});
object.find("a").each((_, a) => {
a = $(a);
a.removeAttr("data-pswp-srcset");
});
return object.html();
}).join("");
const shotDescription = $(".shot-description-container");
const author = `${shotData.shotUser.name}${shotData.shotUser.team.length ? ` for ${shotData.shotUser.team.name}` : ""}`;
return {
description: art(path.join(__dirname, "templates/description-4f32d945.art"), {
shotMedia,
shotData,
description: shotDescription
}),
pubDate: parseDate(shotData.postedOn),
author,
category: shotData.tags
};
}
function ProcessFeed(list) {
return Promise.all(list.map((item) => {
const $ = load(item);
const itemId = $(item).data("thumbnail-id");
const guid = new URL(`/shots/${itemId}`, host).href;
const itemUrl = new URL($(item).find(".shot-thumbnail-link").attr("href"), host).href;
return cache_default.tryGet(guid, async () => {
const { description, pubDate, author, category } = await loadContent(itemUrl);
return {
title: $(".shot-title").text(),
link: itemUrl,
guid,
description,
pubDate,
author,
category
};
});
}));
}
/**
* Retrieves data from a given URL and processes it.
*
* @param {string} url - The URL to retrieve data from.
* @param {string} title - The title of the data.
* @return {Object} - An object containing the retrieved data and metadata.
*/
const getData = async (url, title) => {
const $ = load(await ofetch_default(url));
const result = await ProcessFeed($("ol.dribbbles.group > li").toArray());
return {
title,
link: url,
description: $("meta[name=\"description\"]").attr("content"),
item: result
};
};
var utils_default = { getData };
//#endregion
export { utils_default as t };