UNPKG

rsshub

Version:
53 lines (52 loc) 1.5 kB
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as got_default } from "./got-DUpa1V3-.mjs"; import { load } from "cheerio"; //#region lib/routes/thzt/index.ts const route = { path: "/blog", categories: ["blog"], example: "/thzt/blog", url: "thzt.github.io", name: "Blog", maintainers: ["jihuayu"], handler }; const author = "何幻"; async function handler() { const baseUrl = "https://thzt.github.io"; const targetUrl = `${baseUrl}/archives/`; const response = await got_default({ method: "get", url: targetUrl }); const $ = load(response.data); const list = $("a.post-title-link").toArray().map((item) => { const element = $(item); const link = element.attr("href") || ""; return { title: element.find("span").first().text(), link }; }); return { title: "thzt articles", link: targetUrl, item: await Promise.all(list.slice(0, 15).map((item) => cache_default.tryGet(item.link, async () => { const articleUrl = `${baseUrl}/${item.link}`; const response = await got_default({ method: "get", url: articleUrl }); const $ = load(response.data); const articlePubDate = $("span.post-time > time").text(); item.author = author; item.pubDate = parseDate(articlePubDate); item.description = $("div.post-body").html(); item.category = [$("span.post-category>span>a>span").first().text()]; return item; }))) }; } //#endregion export { route };