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.
| Social cards for every page: og.g1t.sh | 1 | /** |
| 2 | * Part of every cache key: bump it when the cards' design changes, so the | |
| 3 | * cards already cached are drawn again. | |
| 4 | */ | |
| 5 | export const DESIGN = "1"; | |
| 6 | ||
| 7 | /** | |
| 8 | * The address a card is cached under: only the parameters that change it, | |
| 9 | * in order, so stray ones (trackers, cache busters) cannot fill the cache. | |
| 10 | */ | |
| 11 | export function cacheKey(url: URL): string { | |
| 12 | const wanted = | |
| 13 | url.pathname === "/docs" ? ["title", "section", "description"] : url.pathname === "/image" ? ["path", "v"] : []; | |
| 14 | const key = new URL(url.pathname, url.origin); | |
| 15 | key.searchParams.set("design", DESIGN); | |
| 16 | for (const name of wanted) { | |
| 17 | const value = url.searchParams.get(name); | |
| 18 | if (value !== null) key.searchParams.set(name, value); | |
| 19 | } | |
| 20 | return key.toString(); | |
| 21 | } |