UNPKG

rsshub

Version:
46 lines (45 loc) 1.46 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.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 response = await rofetch(currentUrl); const $ = load(response); 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 () => { const detailResponse = await rofetch(item.link); item.description = load(detailResponse)(".blogs-block .col-md-12").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };