diff --git a/src/components/Clock.astro b/src/components/Clock.astro
index c6bc4bd..0331c3a 100644
--- a/src/components/Clock.astro
+++ b/src/components/Clock.astro
@@ -20,15 +20,7 @@ const zone = fmt({ timeZoneName: "short" }).find((p) => p.type === "timeZoneName
aria-label={`zach's local time — ${hour}:${minute} ${mer} ${zone}`}
>
-
-
- {[...hour].map((d) => {d})}
-
- :
-
- {[...minute].map((d) => {d})}
-
-
+ {hour}:{minute}
{mer}
{zone}
@@ -36,82 +28,33 @@ const zone = fmt({ timeZoneName: "short" }).find((p) => p.type === "timeZoneName
diff --git a/src/pages/api/spotify.json.ts b/src/pages/api/spotify.json.ts
index 81e37f3..c0d3914 100644
--- a/src/pages/api/spotify.json.ts
+++ b/src/pages/api/spotify.json.ts
@@ -110,7 +110,7 @@ export const GET: APIRoute = async () => {
const env = getEnv();
const headers = {
"Content-Type": "application/json",
- "Cache-Control": "public, max-age=30, s-maxage=60, stale-while-revalidate=300",
+ "Cache-Control": "public, max-age=120, s-maxage=180, stale-while-revalidate=600",
};
try {
diff --git a/src/pages/api/stats.json.ts b/src/pages/api/stats.json.ts
index 50c652f..30a24f8 100644
--- a/src/pages/api/stats.json.ts
+++ b/src/pages/api/stats.json.ts
@@ -32,7 +32,14 @@ export const GET: APIRoute = async () => {
headers: { "content-type": "application/json", "cache-control": "public, max-age=300" },
});
- const hidden = { configured: false, pageviews: 0, visitors: 0 };
+ const hidden = {
+ configured: false,
+ pageviews: 0,
+ visitors: 0,
+ visits: 0,
+ topPages: [] as { path: string; count: number }[],
+ topReferrers: [] as { ref: string; count: number }[],
+ };
if (!(shareId || (id && key))) return json(hidden);
const headers: Record = { accept: "application/json" };
@@ -56,15 +63,29 @@ export const GET: APIRoute = async () => {
if (!websiteId) return json({ ...hidden, configured: true });
- const url = `${base}/websites/${websiteId}/stats?startAt=0&endAt=${Date.now()}`;
- const res = await fetch(url, { headers });
- const data: any = await res.json();
+ const w = `${base}/websites/${websiteId}`;
+ const range = `startAt=0&endAt=${Date.now()}`;
+ const get = (path: string) => fetch(`${w}/${path}`, { headers }).then((r) => r.json());
- const pageviews = num(data?.pageviews);
- const visitors = num(data?.visitors);
+ const [data, pages, refs] = await Promise.all([
+ get(`stats?${range}`),
+ get(`metrics?${range}&type=path&limit=6`).catch(() => []),
+ get(`metrics?${range}&type=referrer&limit=6`).catch(() => []),
+ ]);
+
+ const pageviews = num((data as any)?.pageviews);
+ const visitors = num((data as any)?.visitors);
+ const visits = num((data as any)?.visits);
if (!pageviews && !visitors) return json({ ...hidden, configured: true });
- return json({ configured: true, pageviews, visitors });
+ const topPages = (Array.isArray(pages) ? pages : [])
+ .map((m: any) => ({ path: String(m?.x ?? ""), count: num(m?.y) }))
+ .filter((p) => p.path);
+ const topReferrers = (Array.isArray(refs) ? refs : [])
+ .map((m: any) => ({ ref: String(m?.x ?? ""), count: num(m?.y) }))
+ .filter((r) => r.ref);
+
+ return json({ configured: true, pageviews, visitors, visits, topPages, topReferrers });
} catch {
return json({ ...hidden, configured: true });
}