Skip to content

Commit bf1a564

Browse files
committed
feat(themes): add random theme selection via ?theme=random
1 parent 4223186 commit bf1a564

3 files changed

Lines changed: 23 additions & 89 deletions

File tree

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ URL Parameter > Theme Default > System Fallback
9292

9393
### Theme Presets
9494

95-
| Theme | Preview | `bg` | `accent` | `text` |
96-
| ------------------ | ------------------- | -------- | -------- | -------- |
97-
| `auto` | System light / dark | _adapts_ | _adapts_ | _adapts_ |
98-
| `dark` _(default)_ | GitHub dark | `0d1117` | `58a6ff` | `c9d1d9` |
99-
| `neon` | Cyberpunk | `000000` | `ff00ff` | `00ffcc` |
100-
| `dracula` | Dracula Pro | `282a36` | `bd93f9` | `f8f8f2` |
101-
| `github` | GitHub green | `0d1117` | `238636` | `ffffff` |
102-
| `light` | Clean & minimal | `ffffff` | `0969da` | `24292f` |
95+
| Theme | Preview | `bg` | `accent` | `text` |
96+
| ------------------ | ------------------------ | -------- | -------- | -------- |
97+
| `auto` | System light / dark | _adapts_ | _adapts_ | _adapts_ |
98+
| `dark` _(default)_ | GitHub dark | `0d1117` | `58a6ff` | `c9d1d9` |
99+
| `neon` | Cyberpunk | `000000` | `ff00ff` | `00ffcc` |
100+
| `dracula` | Dracula Pro | `282a36` | `bd93f9` | `f8f8f2` |
101+
| `github` | GitHub green | `0d1117` | `238636` | `ffffff` |
102+
| `light` | Clean & minimal | `ffffff` | `0969da` | `24292f` |
103+
| `random` | Surprise theme on reload | _varies_ | _varies_ | _varies_ |
103104

104105
> **`auto` uses CSS `@media (prefers-color-scheme)`** inside the SVG so the badge switches between the `light` and `dark` palettes based on the viewer's OS setting — no JavaScript required. This is ideal for GitHub profile READMEs where visitors may use either mode.
105106

app/api/streak/route.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ export async function GET(request: Request) {
2222

2323
const themeName = searchParams.get('theme') || 'dark';
2424
const isAutoTheme = themeName === 'auto';
25-
const selectedTheme = isAutoTheme ? themes.light : themes[themeName] || themes.dark;
25+
const isRandomTheme = themeName === 'random';
26+
const selectedTheme = (() => {
27+
if (isAutoTheme) return themes.light;
28+
if (isRandomTheme) {
29+
const themeKeys = Object.keys(themes);
30+
const randomKey = themeKeys[Math.floor(Math.random() * themeKeys.length)];
31+
return themes[randomKey] || themes.dark;
32+
}
33+
return themes[themeName] || themes.dark;
34+
})();
2635

2736
const rawSpeed = searchParams.get('speed') || '8s';
2837
const speed = /^\d+(\.\d+)?s$/.test(rawSpeed) ? rawSpeed : '8s';
@@ -58,9 +67,10 @@ export async function GET(request: Request) {
5867

5968
// 4. Calculate Cache Control (Reset at UTC Midnight)
6069
const secondsToMidnight = getSecondsUntilUTCMidnight();
61-
const cacheControl = refresh
62-
? 'no-cache, no-store, must-revalidate'
63-
: `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;
70+
const cacheControl =
71+
refresh || isRandomTheme
72+
? 'no-cache, no-store, must-revalidate'
73+
: `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;
6474

6575
// 5. Return the Image Response
6676
return new NextResponse(svg, {

package-lock.json

Lines changed: 0 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)