Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: svg badge v2 (#1314)
Maximilian Kaskedbac8cd44919
diff --git a/apps/docs/src/content/docs/tools/status-badge.mdx b/apps/docs/src/content/docs/tools/status-badge.mdxnew file mode 100644index 000000000..6fe847bad--- /dev/null+++ b/apps/docs/src/content/docs/tools/status-badge.mdx@@ -0,0 +1,75 @@+---+title: Status Badge+description: "Easily embed a badge into your website"+---++## PNG Badge++```html+<img src='https://[slug].openstatus.dev/badge'>+```++This will return a PNG image with the status of your page. It will look like this:+<img src='https://status.openstatus.dev/badge' />++You can customize the theme by adding `?theme=dark` and the size of it by adding `?size=lg`.++Supported themes:+- `dark`+- `light` (default)++Supported sizes:+- `sm` (default)+- `md`+- `lg`+- `xl`++It will display the following labels based on the current status of the status page:++```+Operational+Degraded+Outage+Incident+Maintenance+Unknown+```++## SVG Badge (v2)++```html+<img src='https://[slug].openstatus.dev/badge/v2'>+```++This will return a PNG image with the status of your page. It will look like this:+<img src='https://status.openstatus.dev/badge/v2' />++You can customize the theme by adding `?theme=dark` and the size of it by adding `?size=lg`.++Supported themes:+- `dark`+- `light` (default)++Supported sizes:+- `sm` (default)+- `md`+- `lg`+- `xl`++Compared to the PNG badge, we let you define the `border` and `border-radius` of the SVG badge and the font is mono.++It will display the following labels based on the current status of the status page:++```+All Systems Operational+Degraded Performance+Partial Outage+Major Outage+Ongoing Incident+Under Maintenance+Unknown+```++---++Read more on which status is being shown [here](/tools/status-widget/#how-does-it-work).\ No newline at end of filediff --git a/apps/docs/src/content/docs/tools/status-widget.mdx b/apps/docs/src/content/docs/tools/status-widget.mdxindex 4755cc243..8fe8928ea 100644--- a/apps/docs/src/content/docs/tools/status-widget.mdx+++ b/apps/docs/src/content/docs/tools/status-widget.mdx@@ -287,15 +287,4 @@ import StatusWidget from '../../components/StatusWidget.astro'---<StatusWidget slug="monitor-slug-here" />-```-### SVG Badge--You can also use the SVG badge to display the status of your page.--```html- <img src='https://[slug].openstatus.dev/badge'>-```-This will return an SVG image with the status of your page. It will look like this:-<img src='https://status.openstatus.dev/badge' />--+```\ No newline at end of filediff --git a/apps/web/src/app/status-page/[domain]/badge/route.tsx b/apps/web/src/app/status-page/[domain]/badge/route.tsxindex 2782f7fbb..78254e92c 100644--- a/apps/web/src/app/status-page/[domain]/badge/route.tsx+++ b/apps/web/src/app/status-page/[domain]/badge/route.tsx@@ -32,7 +32,7 @@ const statusDictionary: Record<Status, { label: string; color: string }> = {},under_maintenance: {label: "Maintenance",- color: "bg-gray-500",+ color: "bg-blue-500",},} as const;diff --git a/apps/web/src/app/status-page/[domain]/badge/v2/route.ts b/apps/web/src/app/status-page/[domain]/badge/v2/route.tsnew file mode 100644index 000000000..38e58eaf5--- /dev/null+++ b/apps/web/src/app/status-page/[domain]/badge/v2/route.ts@@ -0,0 +1,91 @@+import type { NextRequest } from "next/server";++import type { Status } from "@openstatus/react";+import { getStatus } from "@openstatus/react";++const statusDictionary: Record<Status, { label: string; hexColor: string }> = {+ operational: {+ label: "All Systems Operational",+ hexColor: "#10b981",+ },+ degraded_performance: {+ label: "Degraded Performance",+ hexColor: "#f59e0b",+ },+ partial_outage: {+ label: "Partial Outage",+ hexColor: "#f59e0b",+ },+ major_outage: {+ label: "Major Outage",+ hexColor: "#ef4444",+ },+ unknown: {+ label: "Unknown",+ hexColor: "#6b7280",+ },+ incident: {+ label: "Ongoing Incident",+ hexColor: "#f59e0b",+ },+ under_maintenance: {+ label: "Under Maintenance",+ hexColor: "#3b82f6",+ },+} as const;++const SIZE: Record<+ string,+ {+ height: number;+ padding: number;+ gap: number;+ radius: number;+ fontSize: number;+ }+> = {+ sm: { height: 34, padding: 8, gap: 12, radius: 4, fontSize: 12 },+ md: { height: 46, padding: 8, gap: 12, radius: 4, fontSize: 14 },+ lg: { height: 56, padding: 12, gap: 16, radius: 6, fontSize: 16 },+ xl: { height: 68, padding: 12, gap: 16, radius: 6, fontSize: 18 },+};++function getTextWidth(text: string, fontSize: number): number {+ const monoCharWidthRatio = 0.6;+ return text.length * monoCharWidthRatio * fontSize;+}++export async function GET(+ req: NextRequest,+ props: { params: Promise<{ domain: string }> },+) {+ const params = await props.params;+ const { status } = await getStatus(params.domain);+ const theme = req.nextUrl.searchParams.get("theme") ?? "light";+ const size = req.nextUrl.searchParams.get("size") ?? "sm";++ const { height, padding, gap, radius, fontSize } = SIZE[size] ?? SIZE.sm;+ const { label, hexColor } = statusDictionary[status];+ const textWidth = getTextWidth(label, fontSize);+ const width = Math.ceil(padding + textWidth + gap + radius * 2 + padding);++ const textColor = theme === "dark" ? "#d1d5db" : "#374151";+ const bgColor = theme === "dark" ? "#111827" : "#ffffff";++ const svg = `+ <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">+ <rect width="${width}" height="${height}" fill="${bgColor}"/>+ <text x="${padding}" y="50%" dominant-baseline="middle"+ font-family="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace" font-size="${fontSize}" font-weight="600" fill="${textColor}">+ ${label}+ </text>+ <circle cx="${width - padding - radius}" cy="${+ height / 2+ }" r="${radius}" fill="${hexColor}"/>+ </svg>+ `;++ return new Response(svg, {+ headers: { "Content-Type": "image/svg+xml" },+ });+}