rsshub
Version:
Make RSS Great Again!
51 lines (49 loc) • 1.62 kB
JavaScript
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { load } from "cheerio";
import markdownit from "markdown-it";
//#region lib/routes/studygolang/utils.ts
const md = markdownit({
html: true,
linkify: true
});
const FetchGoItems = async (ctx, rewriteId) => {
const id = rewriteId || (ctx.req.param("id") ?? "weekly");
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 50;
const rootUrl = "https://studygolang.com";
const currentUrl = `${rootUrl}/go/${id}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $(".right-info .title").slice(0, limit).toArray().map((item) => {
item = $(item);
const a = item.find("a");
return {
title: a.text(),
link: `${rootUrl}${a.attr("href")}`,
author: item.next().find(".author").text(),
category: item.next().find(".node").toArray().map((n) => $(n).text())
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
item.pubDate = timezone(parseDate(content(".timeago").first().attr("title")), 8);
try {
item.description = md.render(content(".content").html());
} catch {}
return item;
})));
return {
title: `Go语言中文网 - ${$(".title h2").text()}`,
link: currentUrl,
item: items
};
};
//#endregion
export { FetchGoItems as t };