rsshub
Version:
Make RSS Great Again!
49 lines (48 loc) • 1.56 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { r as getSubPath } from "./common-utils-DtQojudb.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { n as fixImage, r as fixVideo, t as baseUrl } from "./utils-BIsp_OQ5.mjs";
import { load } from "cheerio";
//#region lib/routes/pikabu/community.ts
const route = {
path: "/community/:name",
categories: ["bbs"],
example: "/pikabu/community/real_true_story",
parameters: { name: "Community name" },
radar: [{
source: ["pikabu.ru/community/:name"],
target: "/community/:name"
}],
name: "Community",
maintainers: ["TonyRL"],
handler
};
async function handler(ctx) {
const { name, sort = "new" } = ctx.req.param();
const type = getSubPath(ctx).split("/", 2)[1];
const { data: response } = await got_default(`${baseUrl}/ajax/${type}/${name}${sort === "default" || type === "tag" ? "" : `/${sort}`}`);
const items = response.data.stories.map((story) => {
const $ = load(story.html, null, false);
const data = JSON.parse($("script[type=\"application/ld+json\"]").text());
const content = $(".story__main");
fixImage(content);
content.find(".player").each((_, elem) => {
fixVideo($(elem));
});
return {
title: data.name,
description: content.find(".story__content-inner").html(),
pubDate: parseDate(data.dateCreated),
author: data.author.name,
link: data.url
};
});
return {
title: response.data.title,
link: `${baseUrl}/${type}/${name}`,
language: "ru-ru",
item: items
};
}
//#endregion
export { route as n, handler as t };