UNPKG

rsshub

Version:
83 lines (81 loc) 2.26 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; //#region lib/routes/hashnode/blog.ts init_esm_shims(); const baseApiUrl = "https://api.hashnode.com"; const route = { path: "/blog/:username", categories: ["blog"], example: "/hashnode/blog/inklings", parameters: { username: "博主名称,用户头像 URL 中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["hashnode.dev/"] }], name: "用户博客", maintainers: ["hnrainll"], handler, url: "hashnode.dev/", description: `::: tip username 为博主用户名,而非\`xxx.hashnode.dev\`中\`xxx\`所代表的 blog 地址。 :::` }; async function handler(ctx) { const username = ctx.req.param("username"); if (!username) return; const query = ` { user(username: "${username}") { publication { posts{ slug title brief coverImage dateAdded } } } } `; const userUrl = `https://${username}.hashnode.dev`; const publication = (await got_default({ method: "POST", url: baseApiUrl, headers: { Referer: userUrl, "Content-type": "application/json" }, body: JSON.stringify({ query }) })).data.data.user.publication; if (!publication) return; const list = publication.posts; return { title: `Hashnode by ${username}`, link: userUrl, item: list.map((item) => ({ title: item.title, description: art(path.join(__dirname, "templates/description-88dc298d.art"), { image: item.coverImage, brief: item.brief }), pubDate: parseDate(item.dateAdded), link: `${userUrl}/${item.slug}` })).filter((item) => item !== "") }; } //#endregion export { route };