rsshub
Version:
Make RSS Great Again!
99 lines (98 loc) • 4.16 kB
JavaScript
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { r as getSubPath } from "./common-utils-Dv4C8Q9Q.mjs";
import { t as got_default } from "./got-BDnf4rdT.mjs";
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
import { raw } from "hono/html";
//#region lib/routes/asiantolick/templates/description.tsx
const Description = ({ description, images }) => /* @__PURE__ */ jsxs(Fragment, { children: [description ? raw(description) : null, images?.map((image, index) => /* @__PURE__ */ jsx("figure", { children: /* @__PURE__ */ jsx("img", {
src: image.src,
alt: image.alt
}) }, `${image.src}-${index}`))] });
const renderDescription = (props) => renderToString(/* @__PURE__ */ jsx(Description, { ...props }));
//#endregion
//#region lib/routes/asiantolick/index.ts
const route = {
path: "/",
categories: ["picture"],
example: "/asiantolick",
radar: [{
source: ["asiantolick.com/"],
target: "/"
}],
name: "Top rated",
maintainers: ["nczitzk"],
handler,
url: "asiantolick.com/",
features: { nsfw: true }
};
async function handler(ctx) {
const category = getSubPath(ctx).slice(1);
const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 24;
const rootUrl = "https://asiantolick.com";
const apiUrl = new URL("ajax/buscar_posts.php", rootUrl).href;
const currentUrl = new URL(category.replace(/^(tag|category)?\/(\d+)/, "$1-$2"), rootUrl).href;
const searchParams = {};
const matches = category.match(/^(tag|category|search|page)?[/-]?(\w+)/);
if (matches) {
const key = matches[1] === "category" ? "cat" : matches[1];
searchParams[key] = matches[2];
}
const { data: response } = await got_default(apiUrl, { searchParams });
let $ = load(response);
let items = $("a.miniatura").slice(0, limit).toArray().map((item) => {
const $item = $(item);
const image = $item.find("div.background_miniatura img");
const link = $item.prop("href");
return {
title: $item.find("div.base_tt").text(),
link,
description: renderDescription({ images: image ? [{
src: image.prop("data-src").split(/\?/, 1)[0],
alt: image.prop("alt")
}] : void 0 }),
author: $item.find(".author").text(),
category: $item.find(".category").toArray().map((c) => $(c).text()),
guid: image ? image.prop("post-id") : link?.match(/\/(\d+)/)?.[1]
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const content = load(detailResponse);
item.title = content("h1").text();
item.description = renderDescription({
description: content("#metadata_qrcode").html() ?? void 0,
images: content("div.miniatura").toArray().map((i) => ({
src: content(i).prop("data-src"),
alt: content(i).find("img").prop("alt")
}))
});
item.author = content(".author").text();
item.category = content("#categoria_tags_post a").toArray().map((c) => content(c).text().trim().replace(/^#/, ""));
item.pubDate = parseDate(detailResponse.match(/"pubDate":\s"((?!http)[^"]*)"/)[1]);
item.updated = parseDate(detailResponse.match(/"upDate":\s"((?!http)[^"]*)"/)[1]);
item.enclosure_url = new URL(`ajax/download_post.php?ver=3&dir=/down/new_${item.guid}&post_id=${item.guid}&post_name=${detailResponse.match(/"title":\s"((?!http)[^"]*)"/)[1]}`, rootUrl).href;
item.guid = `asiantolick-${item.guid}`;
return item;
})));
const { data: currentResponse } = await got_default(currentUrl);
$ = load(currentResponse);
const title = $("title").text().split(/-/, 1)[0].trim();
const icon = $("link[rel=\"icon\"]").first().prop("href");
return {
item: items,
title: title === "Asian To Lick" ? title : `Asian To Lick - ${title}`,
link: currentUrl,
description: $("meta[property=\"og:description\"]").prop("content"),
language: $("html").prop("lang"),
image: $("meta[name=\"msapplication-TileImage\"]").prop("content"),
icon,
logo: icon,
subtitle: title,
allowEmpty: true
};
}
//#endregion
export { route as n, handler as t };