Skip to content

Commit 60986dc

Browse files
committed
fixes
1 parent 85157ed commit 60986dc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/app.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44
<script>
55
(function() {
66
try {
7+
// Check for stored theme
78
const storedTheme = localStorage.getItem('theme');
8-
if (storedTheme) {
9-
document.documentElement.setAttribute('data-theme', storedTheme);
9+
const theme = storedTheme || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
10+
11+
// Set Bootstrap theme attribute
12+
document.documentElement.setAttribute('data-bs-theme', theme);
13+
14+
// If dark theme, inject Darkly CSS immediately to prevent flash
15+
if (theme === 'dark') {
16+
const darkThemeLink = document.createElement('link');
17+
darkThemeLink.rel = 'stylesheet';
18+
darkThemeLink.href = 'https://bootswatch.com/5/darkly/bootstrap.css';
19+
darkThemeLink.integrity = 'sha384-mXM+8P9BUwTXMBS6pzZaBva0g/sZsdn7ZdBimWWpF/1K2kVhkyjQrBznOTf31ui7';
20+
darkThemeLink.crossOrigin = 'anonymous';
21+
darkThemeLink.setAttribute('data-theme', 'dark');
22+
document.head.appendChild(darkThemeLink);
1023
}
1124
} catch (e) {
1225
console.error('Could not apply theme from localStorage', e);
@@ -18,4 +31,4 @@
1831
<body data-sveltekit-preload-data="hover">
1932
<div style="display: contents">%sveltekit.body%</div>
2033
</body>
21-
</html>
34+
</html>

src/routes/+layout.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<link rel="apple-touch-icon" sizes="180x180" href="{assets}/favicon/apple-touch-icon.png" />
3434
<link rel="manifest" href="{assets}/favicon/site.webmanifest" />
3535

36+
<!-- Bootstrap CSS -->
37+
<link
38+
rel="stylesheet"
39+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
40+
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
41+
crossorigin="anonymous" />
42+
3643
<!-- Bootswatch: Darkly theme -->
3744
<link
3845
rel="stylesheet"

0 commit comments

Comments
 (0)