Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.9 kB ยท 56 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { createParser, parseAsStringLiteral } from "nuqs/server";
export const ALL_EMBED_SECTIONS = [ "title", "banner", "components", "feed",] as const;
export type EmbedSection = (typeof ALL_EMBED_SECTIONS)[number];
export type EmbedState = { mode: boolean; sections: EmbedSection[] };
export const embedParser = createParser<EmbedState>({ parse(raw) { if (raw === "" || raw.toLowerCase() === "all") { return { mode: true, sections: [...ALL_EMBED_SECTIONS] }; } const sections = Array.from( new Set( raw .split(",") .map((s) => s.trim().toLowerCase()) .filter((s): s is EmbedSection => (ALL_EMBED_SECTIONS as readonly string[]).includes(s), ), ), ); // If nothing valid was parsed (e.g. `?embed=,` or `?embed=unknown`), // fall back to showing everything rather than a blank embed. if (sections.length === 0) { return { mode: true, sections: [...ALL_EMBED_SECTIONS] }; } return { mode: true, sections }; }, // NOTE: no writer (setEmbed) exists today; the serializer is only reached // if one is added later. Returning "" for `!state.mode` could leak `?embed=` // into the URL when exiting embed mode from a narrowed section set โ // revisit this logic when a writer is added. serialize(state) { if (!state.mode) return ""; if (state.sections.length === ALL_EMBED_SECTIONS.length) return ""; return state.sections.join(","); }, eq: (a, b) => { if (a.mode !== b.mode || a.sections.length !== b.sections.length) return false; const bSet = new Set(b.sections); return a.sections.every((s) => bSet.has(s)); },}).withDefault({ mode: false, sections: [...ALL_EMBED_SECTIONS] });
export const embedThemeParser = parseAsStringLiteral([ "light", "dark",] as const);