g1t/services/og/src/cache.ts

27 lines1,076 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1import { OG_RENDER_VERSION } from "@g1t/contracts/og";
2
Social cards for every page: og.g1t.sh3/**
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas4 * The version of the cards' design, part of every cache key. Bump it (in
5 * `packages/contracts/src/og.ts`, which the site and the docs read too)
6 * whenever the card design changes, so the cards already cached are drawn
7 * again and every page links to a new address.
Social cards for every page: og.g1t.sh8 */
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas9export const RENDER_VERSION = OG_RENDER_VERSION;
Social cards for every page: og.g1t.sh10
11/**
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas12 * The address a card is cached under: the render version, then only the
13 * parameters that change the card, in order, including the page's own
14 * content version `v`, so stray ones (trackers, cache busters) cannot fill
15 * the cache.
Social cards for every page: og.g1t.sh16 */
17export function cacheKey(url: URL): string {
18 const wanted =
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas19 url.pathname === "/docs" ? ["title", "section", "description", "v"] : url.pathname === "/image" ? ["path", "v"] : [];
Social cards for every page: og.g1t.sh20 const key = new URL(url.pathname, url.origin);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas21 key.searchParams.set("render", RENDER_VERSION);
Social cards for every page: og.g1t.sh22 for (const name of wanted) {
23 const value = url.searchParams.get(name);
24 if (value !== null) key.searchParams.set(name, value);
25 }
26 return key.toString();
27}