UNPKG

rsshub

Version:
55 lines (54 loc) 2.15 kB
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"; //#region lib/routes/yuancheng.work/index.ts const route = { path: "/:caty?", categories: ["other"], example: "/yuancheng.work/all", parameters: { caty: "Job category, default to all" }, radar: [{ source: ["yuancheng.work/:caty"], target: (_, url) => url ? `/yuancheng.work/${/\w+-(\w+)-\w+/.exec(url)[1]}` : "/yuancheng.work" }], name: "Remote.work Job Information", maintainers: ["luyuhuang"], description: `| All Jobs | Development | Design | Operation | Product | Function | Other | Marketing | Sales | | :------: | :---------: | :----: | :-------: | :-----: | :------: | :---: | :-------: | :---: | | all | development | design | operation | product | function | other | marketing | sales |`, handler }; const rootUrl = "https://yuancheng.work/"; async function handler(ctx) { const { caty = "all" } = ctx.req.param(); const limit = Number(ctx.req.query("limit") ?? 10); let category; if (caty !== "all") { const slug = `remote-${caty}-jobs`; category = await cache_default.tryGet(`yuancheng.work:category:${slug}`, async () => { const res = await rofetch(`${rootUrl}wp-json/wp/v2/categories`, { query: { slug } }); if (!res.length) throw new Error("Bad category"); return res[0]; }); } const items = (await rofetch(`${rootUrl}wp-json/wp/v2/posts`, { query: { per_page: limit === 10 ? void 0 : Math.min(limit, 100), categories: category?.id, _embed: "" } })).map((post) => ({ title: post.title.rendered, link: post.link, guid: post.guid.rendered, description: post.content.rendered, pubDate: parseDate(post.date_gmt), author: post._embedded.author.map((author) => author.name).join(", "), category: post._embedded["wp:term"].flat().map((term) => term.name) })); return { title: category ? `Remote Work-${caty.charAt(0).toUpperCase() + caty.slice(1)}|远程工作-${category.name}` : "Remote Work|远程工作", link: category ? category.link : rootUrl, item: items }; } //#endregion export { route };