UNPKG

rsshub

Version:
208 lines (203 loc) • 8.96 kB
import dayjs from "dayjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import art from "art-template"; //#region lib/views/atom.tsx const RSS$1 = ({ data }) => /* @__PURE__ */ jsxs("feed", { xmlns: "http://www.w3.org/2005/Atom", "xmlns:rsshub": "http://rsshub.app/xml/schemas", children: [ /* @__PURE__ */ jsx("title", { children: data.title || "RSSHub" }), /* @__PURE__ */ jsx("link", { href: data.link || "https://docs.rsshub.app" }), /* @__PURE__ */ jsx("id", { children: data.id || data.link }), /* @__PURE__ */ jsxs("subtitle", { children: [data.description || data.title, " - Powered by RSSHub"] }), /* @__PURE__ */ jsx("generator", { children: "RSSHub" }), /* @__PURE__ */ jsx("webMaster", { children: "contact@rsshub.app (RSSHub)" }), /* @__PURE__ */ jsx("language", { children: data.language || "en" }), /* @__PURE__ */ jsx("updated", { children: data.lastBuildDate }), /* @__PURE__ */ jsx("author", { children: /* @__PURE__ */ jsx("name", { children: data.author || "RSSHub" }) }), data.icon && /* @__PURE__ */ jsx("icon", { children: data.icon }), data.logo && /* @__PURE__ */ jsx("logo", { children: data.logo }), data.item?.map((item) => /* @__PURE__ */ jsxs("entry", { children: [ /* @__PURE__ */ jsx("title", { children: item.title }), /* @__PURE__ */ jsx("content", { type: "html", src: item.link, children: item.description }), /* @__PURE__ */ jsx("link", { href: item.link }), /* @__PURE__ */ jsx("id", { children: item.guid || item.link || item.title }), item.pubDate && /* @__PURE__ */ jsx("published", { children: item.pubDate }), item.updated && /* @__PURE__ */ jsx("updated", { children: item.updated || item.pubDate }), item.author && /* @__PURE__ */ jsx("author", { children: /* @__PURE__ */ jsx("name", { children: item.author }) }), typeof item.category === "string" ? /* @__PURE__ */ jsx("category", { term: item.category }) : item.category?.map((c) => /* @__PURE__ */ jsx("category", { term: c })), item.media && Object.entries(item.media).map(([key, value]) => { return /* @__PURE__ */ jsx(`media:${key}`, { ...value }); }), item.upvotes ? /* @__PURE__ */ jsx("rsshub:upvotes", { children: item.upvotes }) : "", item.downvotes ? /* @__PURE__ */ jsx("rsshub:downvotes", { children: item.downvotes }) : "", item.comments ? /* @__PURE__ */ jsx("rsshub:comments", { children: item.comments }) : "" ] })) ] }); var atom_default = RSS$1; //#endregion //#region lib/views/json.ts /** * This function should be used by RSSHub middleware only. * @param {object} data ctx.state.data * @returns `JSON.stringify`-ed [JSON Feed](https://www.jsonfeed.org/) */ const json = (data) => { const jsonFeed = { version: "https://jsonfeed.org/version/1.1", title: data.title || "RSSHub", home_page_url: data.link || "https://docs.rsshub.app", feed_url: data.feedLink, description: `${data.description || data.title} - Powered by RSSHub`, icon: data.image, authors: typeof data.author === "string" ? [{ name: data.author }] : data.author, language: data.language || "zh-cn", items: data.item?.map((item) => ({ id: item.guid || item.id || item.link, url: item.link, title: item.title, content_html: item.content && item.content.html || item.description || item.title, content_text: item.content && item.content.text, image: item.image || item.itunes_item_image, banner_image: item.banner, date_published: item.pubDate, date_modified: item.updated, authors: typeof item.author === "string" ? [{ name: item.author }] : item.author, tags: typeof item.category === "string" ? [item.category] : item.category, language: item.language, attachments: item.attachments || (item.enclosure_url ? [{ url: item.enclosure_url, mime_type: item.enclosure_type, title: item.enclosure_title, size_in_bytes: item.enclosure_length, duration_in_seconds: item.itunes_duration }] : void 0), _extra: item._extra || void 0 })) }; return JSON.stringify(jsonFeed); }; var json_default = json; //#endregion //#region lib/views/rss.tsx const RSS = ({ data }) => { const hasItunes = data.itunes_author || data.itunes_category || data.item && data.item.some((i) => i.itunes_item_image || i.itunes_duration); const hasMedia = data.item?.some((i) => i.media); const isTelegramLink = data.link?.startsWith("https://t.me/s/"); return /* @__PURE__ */ jsx("rss", { "xmlns:atom": "http://www.w3.org/2005/Atom", "xmlns:itunes": hasItunes ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : void 0, "xmlns:media": hasMedia ? "http://search.yahoo.com/mrss/" : void 0, version: "2.0", children: /* @__PURE__ */ jsxs("channel", { children: [ /* @__PURE__ */ jsx("title", { children: data.title || "RSSHub" }), /* @__PURE__ */ jsx("link", { children: data.link || "https://docs.rsshub.app" }), /* @__PURE__ */ jsx("atom:link", { href: data.atomlink, rel: "self", type: "application/rss+xml" }), /* @__PURE__ */ jsxs("description", { children: [data.description || data.title, " - Powered by RSSHub"] }), /* @__PURE__ */ jsx("generator", { children: "RSSHub" }), /* @__PURE__ */ jsx("webMaster", { children: "contact@rsshub.app (RSSHub)" }), data.itunes_author && /* @__PURE__ */ jsx("itunes:author", { children: data.itunes_author }), data.itunes_category && /* @__PURE__ */ jsx("itunes:category", { text: data.itunes_category }), data.itunes_author && /* @__PURE__ */ jsx("itunes:explicit", { children: data.itunes_explicit || "false" }), /* @__PURE__ */ jsx("language", { children: data.language || "en" }), data.image && /* @__PURE__ */ jsxs("image", { children: [ /* @__PURE__ */ jsx("url", { children: data.image }), /* @__PURE__ */ jsx("title", { children: data.title || "RSSHub" }), /* @__PURE__ */ jsx("link", { children: data.link }), isTelegramLink && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("height", { children: "31" }), /* @__PURE__ */ jsx("width", { children: "88" })] }) ] }), /* @__PURE__ */ jsx("lastBuildDate", { children: data.lastBuildDate }), /* @__PURE__ */ jsx("ttl", { children: data.ttl }), data.item?.map((item) => /* @__PURE__ */ jsxs("item", { children: [ /* @__PURE__ */ jsx("title", { children: item.title }), /* @__PURE__ */ jsx("description", { children: item.description }), /* @__PURE__ */ jsx("link", { children: item.link }), /* @__PURE__ */ jsx("guid", { isPermaLink: "false", children: item.guid || item.link || item.title }), item.pubDate && /* @__PURE__ */ jsx("pubDate", { children: item.pubDate }), item.author && /* @__PURE__ */ jsx("author", { children: item.author }), item.image && /* @__PURE__ */ jsx("enclosure", { url: item.image, type: "image/jpeg" }), item.itunes_item_image && /* @__PURE__ */ jsx("itunes:image", { href: item.itunes_item_image }), item.enclosure_url && /* @__PURE__ */ jsx("enclosure", { url: item.enclosure_url, length: item.enclosure_length, type: item.enclosure_type }), item.itunes_duration && /* @__PURE__ */ jsx("itunes:duration", { children: item.itunes_duration }), typeof item.category === "string" ? /* @__PURE__ */ jsx("category", { children: item.category }) : item.category?.map((c) => /* @__PURE__ */ jsx("category", { children: c })), item.media && Object.entries(item.media).map(([key, value]) => { return /* @__PURE__ */ jsx(`media:${key}`, { ...value }); }) ] })) ] }) }); }; var rss_default = RSS; //#endregion //#region lib/views/rss3.ts /** * This function should be used by RSSHub middleware only. * @param {object} data ctx.state.data * @returns `JSON.stringify`-ed [UMS Result](https://docs.rss3.io/docs/unified-metadata-schemas) */ const NETWORK = "rsshub"; const TAG = "RSS"; const TYPE = "feed"; const PLATFORM = "RSSHub"; const rss3 = (data) => { const currentUnixTsp = dayjs().unix(); return { data: data.item.map((item) => { const owner = getOwnershipFieldFromURL(item); return { owner, id: item.link, network: NETWORK, from: owner, to: owner, tag: TAG, type: TYPE, direction: "out", feeValue: "0", actions: [{ tag: TAG, type: TYPE, platform: PLATFORM, from: owner, to: owner, metadata: { authors: typeof item.author === "string" ? [{ name: item.author }] : item.author, description: item.description, pub_date: item.pubDate, tags: typeof item.category === "string" ? [item.category] : item.category, title: item.title }, related_urls: [item.link] }], timestamp: dayjs(item.updated).unix() || currentUnixTsp }; }) }; }; function getOwnershipFieldFromURL(item) { try { return new URL(item.link).hostname; } catch { return item.link; } } var rss3_default = rss3; //#endregion export { atom_default as a, json_default as i, rss3_default as n, rss_default as r, art as t };