Skip to content

Commit 7358fb8

Browse files
feat: Add dark mode support to website and blog (feast-dev#6589)
Adds a theme toggle (sun/moon icon) to the navigation bar with localStorage persistence and prefers-color-scheme detection. Replaces all hardcoded light-mode colors with CSS custom properties that adapt under a [data-theme="dark"] selector. Includes flash-prevention via an inline script that sets the theme before first paint. Signed-off-by: Francisco Javier Arceo <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent 66547dc commit 7358fb8

6 files changed

Lines changed: 165 additions & 51 deletions

File tree

‎infra/website/src/components/Navigation.astro‎

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,29 @@
1414
<a href="https://slack.feast.dev/" class="nav-item">COMMUNITY</a>
1515
</div>
1616

17-
<button class="mobile-menu-button" id="mobile-menu-button">
18-
<svg width="24" height="24" fill="none" stroke="currentColor" viewBox="0 0 24 24">
19-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
20-
</svg>
21-
</button>
17+
<div class="nav-right">
18+
<button class="theme-toggle" id="theme-toggle" aria-label="Toggle dark mode">
19+
<svg class="icon-sun" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
20+
<circle cx="12" cy="12" r="5"></circle>
21+
<line x1="12" y1="1" x2="12" y2="3"></line>
22+
<line x1="12" y1="21" x2="12" y2="23"></line>
23+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
24+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
25+
<line x1="1" y1="12" x2="3" y2="12"></line>
26+
<line x1="21" y1="12" x2="23" y2="12"></line>
27+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
28+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
29+
</svg>
30+
<svg class="icon-moon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
31+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
32+
</svg>
33+
</button>
34+
<button class="mobile-menu-button" id="mobile-menu-button">
35+
<svg width="24" height="24" fill="none" stroke="currentColor" viewBox="0 0 24 24">
36+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
37+
</svg>
38+
</button>
39+
</div>
2240
</div>
2341

2442
<div class="mobile-menu" id="mobile-menu">
@@ -38,7 +56,7 @@
3856
top: 0;
3957
left: 0;
4058
right: 0;
41-
background-color: white;
59+
background-color: var(--color-nav-bg);
4260
z-index: 1000;
4361
}
4462

@@ -80,22 +98,50 @@
8098
margin-left: 32px;
8199
}
82100

101+
.nav-right {
102+
display: flex;
103+
align-items: center;
104+
gap: 4px;
105+
padding-right: var(--content-padding);
106+
}
107+
108+
.theme-toggle {
109+
background: none;
110+
border: none;
111+
padding: 8px;
112+
cursor: pointer;
113+
color: var(--color-text);
114+
display: flex;
115+
align-items: center;
116+
justify-content: center;
117+
opacity: 0.7;
118+
transition: opacity 0.2s ease;
119+
}
120+
121+
.theme-toggle:hover {
122+
opacity: 1;
123+
}
124+
125+
.icon-sun { display: none; }
126+
.icon-moon { display: block; }
127+
:global([data-theme="dark"]) .icon-sun { display: block; }
128+
:global([data-theme="dark"]) .icon-moon { display: none; }
129+
83130
.mobile-menu-button {
84131
display: block;
85132
background: none;
86133
border: none;
87134
padding: 8px;
88135
cursor: pointer;
89136
color: var(--color-text);
90-
margin-right: var(--content-padding);
91137
}
92138

93139
@media (min-width: 1024px) {
94140
.desktop-menu {
95141
display: flex;
96142
align-items: center;
97143
}
98-
144+
99145
.mobile-menu-button {
100146
display: none;
101147
}
@@ -104,9 +150,9 @@
104150
.mobile-menu {
105151
display: none;
106152
width: 100%;
107-
background: white;
153+
background: var(--color-nav-bg);
108154
padding: 16px 0;
109-
border-top: 1px solid #eee;
155+
border-top: 1px solid var(--color-border);
110156
position: absolute;
111157
top: 52px;
112158
left: 0;
@@ -122,17 +168,27 @@
122168
}
123169

124170
.mobile-menu a:hover {
125-
background-color: #f5f5f5;
171+
background-color: var(--color-nav-hover);
126172
}
127173
</style>
128174

129175
<script>
130176
const menuButton = document.getElementById('mobile-menu-button');
131177
const mobileMenu = document.getElementById('mobile-menu');
132-
178+
133179
if (menuButton && mobileMenu) {
134180
menuButton.addEventListener('click', () => {
135181
mobileMenu.classList.toggle('active');
136182
});
137183
}
184+
185+
const themeToggle = document.getElementById('theme-toggle');
186+
if (themeToggle) {
187+
themeToggle.addEventListener('click', () => {
188+
const current = document.documentElement.getAttribute('data-theme');
189+
const next = current === 'dark' ? 'light' : 'dark';
190+
document.documentElement.setAttribute('data-theme', next);
191+
localStorage.setItem('theme', next);
192+
});
193+
}
138194
</script>

‎infra/website/src/layouts/BaseLayout.astro‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ const {
5252
<link rel="icon" href="/images/feast_icon-black.png" sizes="192x192">
5353
<link rel="apple-touch-icon" href="/images/feast_icon-black.png">
5454
</head>
55-
<body class="bg-white">
55+
<script is:inline>
56+
(function() {
57+
const saved = localStorage.getItem('theme');
58+
if (saved) {
59+
document.documentElement.setAttribute('data-theme', saved);
60+
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
61+
document.documentElement.setAttribute('data-theme', 'dark');
62+
}
63+
})();
64+
</script>
65+
<body>
5666
<slot name="header" />
5767
<main>
5868
<slot />

‎infra/website/src/layouts/BlogLayout.astro‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { frontmatter } = Astro.props;
1414
<header class="mb-8">
1515
<h1 class="font-mono font-bold text-4xl mb-2">{frontmatter.title}</h1>
1616
{frontmatter.date && (
17-
<time class="font-mono text-sm text-gray-500 block" datetime={frontmatter.date}>
17+
<time class="blog-date" datetime={frontmatter.date}>
1818
{new Date(frontmatter.date).toLocaleDateString('en-US', {
1919
year: 'numeric',
2020
month: 'long',
@@ -34,6 +34,13 @@ const { frontmatter } = Astro.props;
3434
</BaseLayout>
3535

3636
<style>
37+
.blog-date {
38+
font-family: var(--font-mono);
39+
font-size: 0.875rem;
40+
color: var(--color-text-secondary);
41+
display: block;
42+
}
43+
3744
.blog-content {
3845
font-family: var(--font-sans);
3946
}
@@ -77,13 +84,13 @@ const { frontmatter } = Astro.props;
7784

7885
.blog-content :global(code) {
7986
font-family: var(--font-mono);
80-
background-color: #f5f5f5;
87+
background-color: var(--color-surface);
8188
padding: 0.2em 0.4em;
8289
border-radius: 3px;
8390
}
84-
91+
8592
.blog-content :global(pre) {
86-
background-color: #f5f5f5;
93+
background-color: var(--color-surface);
8794
padding: 1em;
8895
border-radius: 5px;
8996
overflow-x: auto;

‎infra/website/src/pages/blog/[slug].astro‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
106106
max-width: 1024px;
107107
padding: 0 20px;
108108
word-break: break-word;
109-
color: rgb(0, 0, 0);
109+
color: var(--color-text);
110110
-webkit-font-smoothing: antialiased;
111111
text-rendering: optimizelegibility;
112112
font-feature-settings: "ss03";
@@ -116,15 +116,15 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
116116
font-family: var(--font-sans);
117117
font-size: 20px;
118118
line-height: 1.5;
119-
color: #666;
119+
color: var(--color-text-secondary);
120120
margin: 0 auto 24px;
121121
max-width: 768px;
122122
}
123123

124124
.blog-meta {
125125
font-family: var(--font-sans);
126126
font-size: 14px;
127-
color: #666;
127+
color: var(--color-text-secondary);
128128
display: flex;
129129
gap: 16px;
130130
justify-content: center;
@@ -197,7 +197,7 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
197197

198198
/* Code blocks */
199199
.blog-content :global(pre) {
200-
background: #f6f8fa;
200+
background: var(--color-surface);
201201
padding: 16px;
202202
border-radius: 4px;
203203
overflow-x: auto;
@@ -207,7 +207,7 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
207207
.blog-content :global(code) {
208208
font-family: var(--font-mono);
209209
font-size: 14px;
210-
background: #f6f8fa;
210+
background: var(--color-surface);
211211
padding: 2px 4px;
212212
border-radius: 3px;
213213
}
@@ -259,7 +259,7 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
259259

260260
.blog-content :global(figcaption) {
261261
font-size: 14px;
262-
color: #666;
262+
color: var(--color-text-secondary);
263263
text-align: center;
264264
margin-top: 8px;
265265
}
@@ -278,9 +278,9 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
278278
.blog-content :global(blockquote) {
279279
margin: 24px 0;
280280
padding-left: 16px;
281-
border-left: 4px solid #ddd;
281+
border-left: 4px solid var(--color-border);
282282
font-style: italic;
283-
color: #555;
283+
color: var(--color-text-secondary);
284284
}
285285

286286
/* Tables */
@@ -293,12 +293,12 @@ const socialImage = heroImage ? toAbsoluteUrl(heroImage) : undefined;
293293
.blog-content :global(th),
294294
.blog-content :global(td) {
295295
padding: 12px;
296-
border: 1px solid #ddd;
296+
border: 1px solid var(--color-border);
297297
text-align: left;
298298
}
299299

300300
.blog-content :global(th) {
301-
background: #f6f8fa;
301+
background: var(--color-surface);
302302
font-weight: 600;
303303
}
304304

‎infra/website/src/pages/blog/index.astro‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const sortedPosts = posts.sort((a, b) => {
7878
max-width: 1024px;
7979
padding: 0 20px;
8080
word-break: break-word;
81-
color: rgb(0, 0, 0);
81+
color: var(--color-text);
8282
-webkit-font-smoothing: antialiased;
8383
text-rendering: optimizelegibility;
8484
font-feature-settings: "ss03";
@@ -88,7 +88,7 @@ const sortedPosts = posts.sort((a, b) => {
8888
font-family: var(--font-sans);
8989
font-size: 20px;
9090
line-height: 1.5;
91-
color: #666;
91+
color: var(--color-text-secondary);
9292
margin: 0 auto 24px;
9393
max-width: 768px;
9494
}
@@ -115,7 +115,7 @@ const sortedPosts = posts.sort((a, b) => {
115115
.post-date {
116116
font-family: var(--font-mono);
117117
font-size: 14px;
118-
color: #666;
118+
color: var(--color-text-secondary);
119119
white-space: nowrap;
120120
}
121121

@@ -147,7 +147,7 @@ const sortedPosts = posts.sort((a, b) => {
147147
.post-authors {
148148
font-family: var(--font-sans);
149149
font-size: 14px;
150-
color: #666;
150+
color: var(--color-text-secondary);
151151
}
152152

153153
@media (max-width: 768px) {

0 commit comments

Comments
 (0)