UNPKG

blogger-feeds

Version:
118 lines (117 loc) 3.2 kB
const h = "https://www.blogger.com", m = "/feeds/posts/default", i = new URLSearchParams({ rewriteforssl: "true", dynamicviews: "1", alt: "json", v: "2" }); i.sort(); const p = { max: 150, def: 25, min: 1 }, g = /* @__PURE__ */ new Set(["published", "updated"]), d = /* @__PURE__ */ new Set([ "published-max", "published-min", "updated-max", "updated-min" ]), u = /* @__PURE__ */ new Set([ ...Array.from(i.keys()), ...Array.from(d), "start-index", "max-results", "orderby", "q" ]), w = (e, s) => isNaN((e = new Date(e ?? (e = ""))).valueOf()) ? "" : (s = /^[\+\-]?\d{2}\:\d{2}$/.test((s ?? (s = "")) + "") ? s : "", e.toJSON().split(".").at(0) + s), n = (e, s, t) => { switch (s) { case "origin": case "blog": e.href = e.href.replace(e.origin, t); break; case "pathname": case "path": e.pathname = t; break; case "search": case "searchParams": e.search = t; break; case "href": e.href = t; break; } return e; }, c = ({ num: e, min: s = Number.MIN_SAFE_INTEGER, max: t = Number.MAX_SAFE_INTEGER, def: a }) => Number.isSafeInteger(e = Math.max(Math.min(Number(e), t), s)) ? e : a, r = (e, s, t) => { const a = e.searchParams; return s && (t ?? (t = "") ? a.set(s, t + "") : a.delete(s)), a; }, R = (e) => (e.href = decodeURIComponent(e.href), e.searchParams.sort(), e), x = (e, s) => { try { return new URL(e, s); } catch { return null; } }, S = (e, s) => { let t = m; if (_(e) && (s.blog = "blogger"), (s == null ? void 0 : s.blog) === "blogger") if (b((s == null ? void 0 : s.blogId) + "")) t = m.replace("feeds", "feeds/" + s.blogId); else throw new Error("invalid conf.blogID"); n(e, "path", t), n(e, "search", i + ""); }, A = (e, s) => { for (let [t, a] of r(e)) !(u.has(t) && a) && r(e, t, ""); }, E = (e, s) => { for (const t of d) r(e, t, w(s[t])); }, f = (e, s) => { const t = "max-results", a = "start-index", o = "orderby"; r( e, t, c({ num: s[t], ...p }) + "" ), r(e, o, g.has(s[o]) ? s[o] : "published"), r( e, a, c({ num: s[a], min: 1, def: 1 }) + "" ); }, l = (e) => Array.isArray(e) ? e.map(l).filter(Boolean).sort().join(",") : (e == null ? void 0 : e.trim()) ?? "", I = (e) => Array.from(new Set(e.map(l))).filter(Boolean).map((s) => "label:" + s).sort().join("|"), y = (e, s) => { var a; const t = [ s.labels ? I(s.labels) : "", ((a = s.terms) == null ? void 0 : a.trim()) ?? "" ].join(" ").trim(); t && r(e, "q", t); }, L = (e, s) => !!(b((s == null ? void 0 : s.postId) ?? "") && n(e, "path", e.pathname + "/" + s.postId)), N = [S, L, f, E, y, A], O = (e) => { try { const s = new URL(e.blog === "blogger" ? h : e.blog); for (const t of N) if (t(s, e)) break; return R(s); } catch (s) { return console.error(s, e), null; } }, b = (e) => (e + "").match(/\d{7,}/g), _ = (e) => (e + "").includes(h), P = (e) => { var s; return (s = (e + "").match(/^(.*?\|?label\:(?:\w|\,)*){1,}/)) == null ? void 0 : s.at(0); }; export { P as a, b, w as c, _ as i, O as m, x as s };