-
Notifications
You must be signed in to change notification settings - Fork 17
Fix theme toggle issue on "How it works " page and Implement Cache Busting #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rudra-rps
wants to merge
10
commits into
OWASP-BLT:main
Choose a base branch
from
Rudra-rps:feat/theme_toggle_how_it_works
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
221a952
Fix theme toggle binding and disable dev caching
Rudra-rps 1f4b658
resolve merge conflictS
Rudra-rps 59868f1
Fixes copilot review around Cache control, Dark mode fallback, DOMCon…
Rudra-rps ed268fb
implement content-hash cache busting for static assets
Rudra-rps 8357801
Merge remote-tracking branch 'upstream/main' into feat/theme_toggle_h…
Rudra-rps b9d5f9c
resolved conflicts markers
Rudra-rps 6ff0a55
Fix error reporting safety, theme accessibility, and asset fingerprin…
Rudra-rps add8e61
Sanitize all frontend error reporting paths
Rudra-rps ce579e1
resolved flagged issues by coderabbit
Rudra-rps b09c98e
Merge origin/main into feat/theme_toggle_how_it_works
Rudra-rps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Shared theme utilities for BLT-Leaf | ||
| // - sets Tailwind config for dark mode | ||
| // - applies the saved or preferred theme early to avoid FOUC | ||
| // - provides `toggleTheme()` and wires up theme icons/toggles on DOMContentLoaded | ||
|
|
||
Rudra-rps marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| window.tailwind = window.tailwind || {}; | ||
| window.tailwind.config = window.tailwind.config || {}; | ||
| window.tailwind.config.darkMode = 'class'; | ||
|
|
||
| (function applyInitialTheme() { | ||
| try { | ||
| const savedTheme = localStorage.getItem('theme'); | ||
| if (savedTheme === 'dark') { | ||
| document.documentElement.classList.add('dark'); | ||
| } else if (savedTheme === 'light') { | ||
| document.documentElement.classList.remove('dark'); | ||
| } else { | ||
| // No explicit saved theme: respect the OS/browser preference. | ||
| if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
| document.documentElement.classList.add('dark'); | ||
| } else { | ||
| document.documentElement.classList.remove('dark'); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| // Storage unavailable — leave any theme class already set in the <head> as-is. | ||
| } | ||
| })(); | ||
|
|
||
| function updateThemeIcons() { | ||
| const icons = document.querySelectorAll('[data-theme-icon]'); | ||
| icons.forEach(icon => { | ||
| const isTextXs = icon.classList.contains('text-xs'); | ||
| const base = document.documentElement.classList.contains('dark') ? 'fas fa-sun' : 'fas fa-moon'; | ||
| icon.className = base + (isTextXs ? ' text-xs' : ''); | ||
| }); | ||
| } | ||
|
|
||
| function toggleTheme() { | ||
| const isDark = document.documentElement.classList.contains('dark'); | ||
| if (isDark) { | ||
| document.documentElement.classList.remove('dark'); | ||
| try { localStorage.setItem('theme', 'light'); } catch (e) {} | ||
| } else { | ||
| document.documentElement.classList.add('dark'); | ||
| try { localStorage.setItem('theme', 'dark'); } catch (e) {} | ||
| } | ||
| updateThemeIcons(); | ||
| } | ||
|
|
||
| document.addEventListener('DOMContentLoaded', function () { | ||
| updateThemeIcons(); | ||
| document.querySelectorAll('[data-theme-toggle]') | ||
| .forEach(btn => btn.addEventListener('click', toggleTheme)); | ||
| }); | ||
|
|
||
| // Export for other scripts | ||
| window.toggleTheme = toggleTheme; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.