UNPKG

rsshub

Version:
62 lines (61 loc) 2.2 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"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc.js"; import timezonePlugin from "dayjs/plugin/timezone.js"; //#region lib/routes/iciba/index.ts dayjs.extend(utc); dayjs.extend(timezonePlugin); const route = { path: "/:days?/:img_type?", categories: ["study"], example: "/iciba/7/poster", parameters: { days: "number of items to show (min = 1, max = 7, default = 1)", img_type: "image style" }, description: `| \`:img_type\` | image style | | ----------- | -------------- | | original | Original size | | medium | Medium size | | thumbnail | Thumbnail size | | poster | Art poster |`, name: "Daily English Sentence", maintainers: ["mashirozx"], handler }; async function handler(ctx) { const { days: daysParam, img_type: imgTypeParam } = ctx.req.param(); const days = Math.min(Math.max(Number.parseInt(daysParam) || 1, 1), 7); const imgTypes = { original: "picture4", medium: "picture2", thumbnail: "picture3", poster: "fenxiang_img" }; const imgType = imgTypes[imgTypeParam] ?? imgTypes.original; const data = await Promise.all(Array.from({ length: days }, (_, x) => { const link = `https://open.iciba.com/dsapi/?date=${dayjs().tz("Asia/Shanghai").subtract(x, "day").format("YYYY-MM-DD")}`; return cache_default.tryGet(link, () => rofetch(link, { parseResponse: JSON.parse })); })); return { title: "金山词霸每日一句", link: "https://news.iciba.com/", itunes_author: "金山词霸每日一句", itunes_category: "Learn English", image: data[0].picture3, item: data.map((item) => ({ title: item.content, description: `${item.content}<br>${item.note}<br><img src="${item[imgType]}">`, pubDate: timezone(parseDate(item.dateline), 8), link: `http://news.iciba.com/views/dailysentence/daily.html#!/detail/title/${item.dateline}`, itunes_item_image: item.picture3, enclosure_url: item.tts, enclosure_type: "audio/mpeg" })) }; } //#endregion export { route };