💄 make darkmode standard theme when no javascript

Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-02-22 15:22:10 +01:00
parent de636d43d6
commit 791fe66ccf
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6
3 changed files with 34 additions and 34 deletions

View file

@ -8,9 +8,9 @@ const today = new Date();
const updateImageForTheme = () => {
const currentTheme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
githubImage.src = currentTheme === 'dark' ? '/socials/github_dark.svg' : '/socials/github_light.svg';
spotifyImage.src = currentTheme === 'dark' ? '/socials/spotify_dark.svg' : '/socials/spotify_light.svg';
webringImage.src = currentTheme === 'dark' ? '/socials/webring_dark.svg' : '/socials/webring_light.svg';
githubImage.src = currentTheme === 'dark' ? '/socials/github_light.svg' : '/socials/github_dark.svg';
spotifyImage.src = currentTheme === 'dark' ? '/socials/spotify_light.svg' : '/socials/spotify_dark.svg';
webringImage.src = currentTheme === 'dark' ? '/socials/webring_light.svg' : '/socials/webring_dark.svg';
};
updateImageForTheme();
@ -25,13 +25,13 @@ const today = new Date();
<div>Sindre Kjelsrud &copy; {today.getFullYear()}</div>
<div class="flex gap-1">
<a href="https://github.com/SindreKjelsrud" aria-label="Link to my GitHub">
<img id="githubImage" height="30" width="30" src="/socials/github_light.svg" alt="GitHub"/>
<img id="githubImage" height="30" width="30" src="/socials/github_dark.svg" alt="GitHub"/>
</a>
<a href="https://open.spotify.com/user/kjelsrud!" aria-label="Link to my Spotify">
<img id="spotifyImage" height="30" width="30" src="/socials/spotify_light.svg" alt="Spotify"/>
<img id="spotifyImage" height="30" width="30" src="/socials/spotify_dark.svg" alt="Spotify"/>
</a>
<a href="https://webring.xxiivv.com/#sid" target="_blank" rel="noopener">
<img id="webringImage" height="30" width="30" src="/socials/webring_light.svg" alt="XXIIVV webring"/>
<img id="webringImage" height="30" width="30" src="/socials/webring_dark.svg" alt="XXIIVV webring"/>
</a>
</div>
</footer>

View file

@ -12,12 +12,12 @@
border: 0;
background: none;
}
.sun { fill: #3B2C29; }
.moon { fill: transparent; }
.sun { fill: transparent; }
.moon { fill: #9AD3BB; }
:global(.dark) .sun { fill: transparent; }
:global(.dark) .moon { fill: #9AD3BB; }
:global(.dark) .sun { fill: #3B2C29; }
:global(.dark) .moon { fill: transparent; }
</style>
<script is:inline>
@ -25,16 +25,16 @@
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
return localStorage.getItem('theme');
}
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark';
}
if (window.matchMedia('(prefers-color-scheme: light)').matches) {
return 'light';
}
return 'dark';
})();
if (theme === 'light') {
document.documentElement.classList.remove('dark');
if (theme === 'dark') {
document.documentElement.classList.remove('light');
} else {
document.documentElement.classList.add('dark');
document.documentElement.classList.add('light');
}
window.localStorage.setItem('theme', theme);