rsshub
Version:
Make RSS Great Again!
44 lines (43 loc) • 1.39 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/naceweb/blog.ts
const route = {
path: "/blog/:sort?",
categories: ["new-media"],
example: "/naceweb/blog",
parameters: { sort: "Sort, see below, Most Recent by default" },
name: "Blog",
maintainers: ["nczitzk"],
handler,
description: `| Most Recent | Top Rated | Most Read |
| ----------- | --------- | ------------- |
| | top-blogs | mostreadblogs |`
};
async function handler(ctx) {
const { sort = "" } = ctx.req.param();
const currentUrl = `https://community.naceweb.org/browse/blogs/${sort}`;
const $ = load(await rofetch(currentUrl));
const list = $(".BlogTitle").slice(0, 10).toArray().map((item) => {
const $item = $(item);
const link = $item.attr("href");
const split = link.split("/");
return {
link,
title: $item.text(),
pubDate: parseDate(`${split[5]}-${split[6]}-${split[7]}`)
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
item.description = load(await rofetch(item.link))(".blogs-block .col-md-12").html();
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };