Commit 81c071c
authored
feat(themes): add random theme selection via ?theme=random (JhaSourav07#115)
## Description
Fixes JhaSourav07#66
Adds support for ?theme=random as a valid theme value on the /api/streak
endpoint. When passed, the API dynamically picks a random theme from the
available themes object on every request, giving users a surprise theme
on every load.
- Changes made in app/api/streak/route.ts:
Added an isRandomTheme flag that checks if theme === 'random'. If true,
a random key is picked from the themes object using Math.random(), with
a || themes.dark fallback to ensure no crash if the selection somehow
fails.
- Also extended the cacheControl condition to disable caching when
isRandomTheme is true:
const cacheControl = refresh || isRandomTheme
? 'no-cache, no-store, must-revalidate'
: `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;
Without this, the CDN would cache the first random SVG and serve the
same theme to all users for hours, defeating the purpose of the feature
entirely.
- Changes made in README.md:
Added random to the Theme Presets table with _varies_ for all color
columns since the values change dynamically on every load.
No other files were modified.
## Pillar
- 🛠️ Other (Bug fix, refactoring, docs)
## Working Video
https://collection.cloudinary.com/dqvm8dce2/73286b27f012f3021856fee1142847bf
## Checklist before requesting a review:
- I have read the `CONTRIBUTING.md` file.
- I have tested these changes locally
(`localhost:3000/api/streak?user=YOUR_USERNAME&theme=random`).
- I have run `npm run format` and `npm run lint` locally and resolved
all errors.
- My commits follow the Conventional Commits format.
- I have updated `README.md` added a new 'random' theme preset.
- I have started the repo.
- I have made sure that i have only one commit to merge in this PR.3 files changed
Lines changed: 23 additions & 89 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
| |||
58 | 67 | | |
59 | 68 | | |
60 | 69 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments