Replace hard-coded hex values and ad-hoc `dark:` variants with a single
semantic token layer in `src/styles/global.css` (`@theme` + `html.dark`
re-declaration), so every component uses the same Tailwind class list in
both modes.
Key changes:
- Define semantic tokens (page, surface, ink, accent, edge, etc.) and raw
ingredient palette (--color-spaghetti-*, --color-marinara*, etc.)
- Configure dual Shiki themes (light-plus / everforest-dark) with
`defaultColor: false` for proper per-mode code block colours, replacing
the old `.prose pre { #1f2937 !important }` hack
- Tint background particles to match the warm cream/espresso palette
instead of pure black dots
- Document theme rules: add tokens not `dark:` variants, keep colour rules
inside `@layer`, never target Tailwind utility classes with unlayered
overrides, route prose colours through `--tw-prose-*` only
All text and interactive elements meet WCAG AA contrast (4.5:1 body, 3:1
large/interactive). Light mode is a warm cream plate with white cards; dark
mode is espresso (#140C08) with raised cards.
173 lines
5.0 KiB
Plaintext
173 lines
5.0 KiB
Plaintext
---
|
|
import type { StatusSnapshot } from "@lib/status"
|
|
|
|
interface Props {
|
|
snapshot: StatusSnapshot
|
|
}
|
|
|
|
const { snapshot } = Astro.props
|
|
|
|
// Refresh cadence for the browser. The server already caches Uptime Kuma for a
|
|
// minute, so polling faster than that only adds requests without new signal.
|
|
const REFRESH_MS = 60_000
|
|
|
|
function details(s: StatusSnapshot): string {
|
|
const { total, up, down, pending, maintenance } = s.summary
|
|
if (s.state === "unknown") {
|
|
return s.reason === "stale"
|
|
? "Uptime Kuma has not reported recently"
|
|
: "Status could not be read"
|
|
}
|
|
const parts = [`${up}/${total} monitors up`]
|
|
if (down > 0) parts.push(`${down} down`)
|
|
if (pending > 0) parts.push(`${pending} pending`)
|
|
if (maintenance > 0) parts.push(`${maintenance} in maintenance`)
|
|
if (s.incidents > 0) parts.push(`${s.incidents} incident${s.incidents === 1 ? "" : "s"}`)
|
|
return parts.join(", ")
|
|
}
|
|
|
|
const state = snapshot.state
|
|
const label = snapshot.label
|
|
const detailsText = details(snapshot)
|
|
---
|
|
|
|
<a
|
|
href={snapshot.statusPageUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
class="status group flex gap-2 justify-center sm:justify-end items-center text-ink-muted hover:text-ink"
|
|
data-status-root
|
|
data-status={state}
|
|
data-refresh-ms={REFRESH_MS}
|
|
data-checked-at={snapshot.checkedAt}
|
|
aria-label={`System status: ${label}. ${detailsText}. Open status page`}
|
|
title={detailsText}
|
|
>
|
|
<span class="relative flex h-3 w-3" aria-hidden="true">
|
|
<span class="ping animate-ping absolute inline-flex h-full w-full rounded-full"></span>
|
|
<span class="core relative inline-flex rounded-full h-3 w-3"></span>
|
|
</span>
|
|
<span data-status-label>{label}</span>
|
|
</a>
|
|
|
|
<style>
|
|
/* Colours hang off data-status so the client script only has to flip one
|
|
attribute; Tailwind cannot generate classes built at runtime anyway. */
|
|
.status {
|
|
transition: color 300ms ease-in-out;
|
|
}
|
|
|
|
.core {
|
|
background-color: var(--color-status-ok);
|
|
transition: background-color 300ms ease-in-out;
|
|
}
|
|
|
|
.ping {
|
|
background-color: var(--color-status-ok-ping);
|
|
}
|
|
|
|
[data-status="degraded"] .core {
|
|
background-color: var(--color-status-warn);
|
|
}
|
|
[data-status="degraded"] .ping {
|
|
background-color: var(--color-status-warn-ping);
|
|
}
|
|
|
|
[data-status="down"] .core {
|
|
background-color: var(--color-status-down);
|
|
}
|
|
[data-status="down"] .ping {
|
|
background-color: var(--color-status-down-ping);
|
|
}
|
|
|
|
[data-status="maintenance"] .core {
|
|
background-color: var(--color-status-maint);
|
|
}
|
|
[data-status="maintenance"] .ping {
|
|
background-color: var(--color-status-maint-ping);
|
|
}
|
|
|
|
[data-status="unknown"] .core {
|
|
background-color: var(--color-status-unknown);
|
|
}
|
|
[data-status="unknown"] .ping {
|
|
display: none;
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.ping {
|
|
display: none;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
const root = document.querySelector<HTMLElement>("[data-status-root]")
|
|
const labelNode = root?.querySelector<HTMLElement>("[data-status-label]")
|
|
|
|
if (root && labelNode) {
|
|
const refreshMs = Number(root.dataset.refreshMs) || 60_000
|
|
let timer: ReturnType<typeof setInterval> | null = null
|
|
|
|
const render = (snapshot: {
|
|
state: string
|
|
label: string
|
|
summary?: { up: number; total: number }
|
|
}) => {
|
|
root.dataset.status = snapshot.state
|
|
labelNode.textContent = snapshot.label
|
|
const details = snapshot.summary
|
|
? `${snapshot.summary.up}/${snapshot.summary.total} monitors up`
|
|
: ""
|
|
root.title = details || snapshot.label
|
|
root.setAttribute(
|
|
"aria-label",
|
|
`System status: ${snapshot.label}. ${details}. Open status page`
|
|
)
|
|
}
|
|
|
|
const refresh = async () => {
|
|
try {
|
|
const response = await fetch("/api/status", {
|
|
headers: { accept: "application/json" },
|
|
cache: "default",
|
|
})
|
|
if (!response.ok) throw new Error(`status endpoint returned ${response.status}`)
|
|
render(await response.json())
|
|
} catch {
|
|
// The site's own route failed (or Uptime Kuma is unreachable). Say so
|
|
// rather than leaving a confident green light on a dead stack.
|
|
root.dataset.status = "unknown"
|
|
labelNode.textContent = "Status unavailable"
|
|
}
|
|
}
|
|
|
|
const start = () => {
|
|
if (timer !== null) return
|
|
timer = setInterval(refresh, refreshMs)
|
|
}
|
|
|
|
const stop = () => {
|
|
if (timer === null) return
|
|
clearInterval(timer)
|
|
timer = null
|
|
}
|
|
|
|
// A background tab should not burn requests; refresh the moment it is seen.
|
|
document.addEventListener("visibilitychange", () => {
|
|
if (document.hidden) stop()
|
|
else {
|
|
void refresh()
|
|
start()
|
|
}
|
|
})
|
|
|
|
// No immediate fetch when the server just rendered the state. Prerendered
|
|
// routes (blog posts, legal pages) bake the build-time snapshot, so compare
|
|
// timestamps and refresh straight away if what we were handed is old.
|
|
const checkedAt = Date.parse(root.dataset.checkedAt ?? "")
|
|
if (Number.isNaN(checkedAt) || Date.now() - checkedAt > refreshMs) void refresh()
|
|
start()
|
|
}
|
|
</script>
|