rsshub
Version:
Make RSS Great Again!
49 lines (48 loc) • 1.86 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 { load } from "cheerio";
//#region lib/routes/proletar/index.ts
const route = {
path: "/:type?/:id?",
categories: ["new-media"],
example: "/proletar",
parameters: {
type: "类型,`categories` 分类或 `tags` 标签,默认为全部文章",
id: "分类见下表,标签名参见 [所有标签](https://review.proletar.ink/tags)"
},
name: "分类 / 标签",
maintainers: ["nczitzk"],
description: `| 全部文章 | 中流击水 | 革命文艺 | 当代中国 | 理论视野 | 国际观察 | 史海沉钩 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| | 中流击水 | 革命文艺 | 当代中国 | 理论视野 | 国际观察 | 史海沉钩 |`,
handler
};
async function handler(ctx) {
const { type = "", id = "" } = ctx.req.param();
const rootUrl = "https://review.proletar.ink";
const currentUrl = `${rootUrl}/${type === "" && id === "" ? "posts" : `${type}/${id}`}/`;
const $ = load(await rofetch(currentUrl));
const list = $(".archive-item-link").toArray().slice(0, 15).map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: `${rootUrl}${$item.attr("href")}`
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await rofetch(item.link);
const content = load(detailResponse);
item.author = content(".post-author").text();
item.description = content("#content").html();
item.pubDate = parseDate(detailResponse.match(/"datePublished":"(.*)","dateModified"/)[1]);
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };