Skip to content

Commit dbb2e26

Browse files
authored
feat(style): use high-contrast themes for code blocks (#538)
1 parent 1c66b54 commit dbb2e26

File tree

8 files changed

+81
-17
lines changed

8 files changed

+81
-17
lines changed

astro.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import searchIndex from "./src/lib/search-index.js"
2020
import sitemap from "@astrojs/sitemap"
2121
import tailwindcss from "@tailwindcss/vite"
2222
import { addCopyButton } from "shiki-transformer-copy-button"
23+
import { SHIKI_THEMES } from "./src/const.ts"
2324

2425
// https://astro.build/config
2526
export default defineConfig({
@@ -60,7 +61,8 @@ export default defineConfig({
6061
syntaxHighlight: "shiki",
6162
// https://github.com/shikijs/shiki/blob/main/docs/languages.md
6263
shikiConfig: {
63-
theme: "nord",
64+
themes: SHIKI_THEMES,
65+
defaultColor: false,
6466
// You can add options to the transformer here
6567
// For example, to change the 'copied' state duration:
6668
// toggle: 3000, // 3 seconds

src/components/AnimatedTerminal.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ ${versionLine}
246246
</script>
247247

248248
<div class="terminal-wrapper rounded-lg shadow-lg" style="background: #2e3440;" data-latest-release={latestRelease}>
249-
<div class={`top-bar flex p-3 space-x-2 rounded-t-lg`}>
249+
<div class="top-bar flex p-3 space-x-2 rounded-t-lg" style="background: #2e3440;">
250250
<div class="block rounded-full bg-slate-500 w-3 h-3"></div>
251251
<div class="block rounded-full bg-slate-500 w-3 h-3"></div>
252252
<div class="block rounded-full bg-slate-500 w-3 h-3"></div>

src/components/Contributors.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const contributors = await getContributors()
3030
<Sponsors size="large" align="center" />
3131
</div>
3232

33-
<h3 class="text-base font-mono text-navy-300 text-center mb-8 dark:text-navy-100">
33+
<h3 class="mt-24 mb-8 text-base font-mono text-navy-300 text-center dark:text-navy-100">
3434
GitHub Contributors
3535
</h3>
3636
<div class="max-w-5xl mx-auto flex flex-wrap justify-center">

src/components/Header.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ import ThemeToggle from "./ThemeToggle.astro"
6868
src="/logos/ddev.svg"
6969
alt="DDEV logo"
7070
aria-hidden="true"
71+
width="293"
72+
height="69"
7173
/>
7274
<img
7375
class="h-8 w-auto sm:h-10 hidden dark:block"
7476
src="/logos/dark-ddev.svg"
7577
alt="DDEV logo"
7678
aria-hidden="true"
79+
width="293"
80+
height="69"
7781
/>
7882
</a>
7983
<div class="w-2/3 flex justify-end items-center gap-6">

src/components/Terminal.astro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Code } from "astro/components" // Keep this import
1515
// 1. Import the transformer here!
1616
import { addCopyButton } from 'shiki-transformer-copy-button';
1717
import type { ShikiTransformer } from 'shiki';
18+
import { SHIKI_THEMES } from '../const';
1819
1920
export interface Props {
2021
code: string
@@ -27,11 +28,14 @@ export interface Props {
2728
| "windows-terminal"
2829
| "ubuntu"
2930
// Added a language prop for Shiki, defaults to 'bash'
30-
lang?: 'bash' | 'sh' | 'powershell' | 'text'
31+
lang?: 'bash' | 'sh' | 'powershell' | 'text'
3132
}
3233
3334
// Destructure props, adding a default for lang
34-
const { code, codeTheme = "nord", type = "default", lang = "bash" } = Astro.props
35+
const { code, type = "default", lang = "bash" } = Astro.props
36+
37+
// Use dual themes for light/dark mode support
38+
const codeThemes = SHIKI_THEMES
3539
3640
const promptSymbols = {
3741
default: '',
@@ -146,6 +150,6 @@ const componentTransformers = [
146150
)}
147151
</div>
148152
<div class="terminal-code-container my-0">
149-
<Code code={rawCode} lang={lang} theme={codeTheme} transformers={componentTransformers} />
153+
<Code code={rawCode} lang={lang} themes={codeThemes} defaultColor={false} transformers={componentTransformers} />
150154
</div>
151155
</div>

src/components/quickstart/Cloud.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Tabs from "@components/Tabs.astro"
44
import { Code } from "astro/components"
55
import CommunityCTA from "./CommunityCTA.astro"
66
import Examples from "./Examples.astro"
7+
import { SHIKI_THEMES } from "../../const"
78
89
export interface Props {
910
latestVersion: string
@@ -41,7 +42,8 @@ const { latestVersion } = Astro.props
4142
}
4243
}
4344
`}
44-
theme="nord"
45+
themes={SHIKI_THEMES}
46+
defaultColor={false}
4547
lang="json"
4648
/>
4749
</li>

src/const.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export const ORG_SAME_AS = [
3232
"https://localdev.foundation",
3333
]
3434
export const BLOG_DESCRIPTION = `Posts about DDEV, Docker, and local development.`
35+
export const SHIKI_THEMES = {
36+
light: "github-light-high-contrast",
37+
dark: "github-dark-high-contrast",
38+
} as const

src/styles/global.css

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
@config "../../tailwind.config.cjs";
33
@import "./callouts.css";
44

5+
:root {
6+
--code-bg-light: #dfe2e7;
7+
--code-bg-dark: #2e3440;
8+
}
9+
510
header {
611
a[target="_blank"] {
712
&::after {
@@ -86,7 +91,7 @@ input[type="radio"]:checked + label {
8691

8792
.terminal-wrapper {
8893
@apply rounded-lg;
89-
background: #2e3440;
94+
background: var(--code-bg-light);
9095
img {
9196
margin-top: 0px;
9297
margin-bottom: 0px;
@@ -95,28 +100,44 @@ input[type="radio"]:checked + label {
95100
@apply font-normal overflow-x-auto font-mono bg-transparent rounded-t-none;
96101

97102
code {
98-
color: #d8dee9;
99103
.prompt {
100-
@apply select-none text-slate-400;
104+
@apply select-none opacity-60;
101105
}
102106
}
103107
}
104108
}
105109

110+
html.dark .terminal-wrapper {
111+
background: var(--code-bg-dark);
112+
}
113+
106114
.terminal-wrapper .top-bar {
115+
background: var(--code-bg-light);
116+
107117
&.powershell {
108-
@apply justify-between text-white;
109-
background: #1f2023;
118+
@apply justify-between text-gray-800 bg-gray-300;
110119
}
111120
&.powershell-ubuntu {
112-
@apply justify-between text-white;
113-
background: #1f2023;
121+
@apply justify-between text-gray-800 bg-gray-300;
114122
}
115123
&.ubuntu {
116124
@apply justify-end;
117125
}
118126
}
119127

128+
html.dark .terminal-wrapper .top-bar {
129+
background: var(--code-bg-dark);
130+
131+
&.powershell {
132+
@apply text-white;
133+
background: #1f2023;
134+
}
135+
&.powershell-ubuntu {
136+
@apply text-white;
137+
background: #1f2023;
138+
}
139+
}
140+
120141
.prose .terminal-wrapper pre {
121142
@apply my-0;
122143
}
@@ -172,6 +193,19 @@ pre.astro-code code {
172193
padding-bottom: 2px;
173194
}
174195

196+
/* Shiki dual theme support - override backgrounds for better contrast */
197+
pre.astro-code,
198+
pre.astro-code span {
199+
color: var(--shiki-light) !important;
200+
background-color: var(--code-bg-light) !important;
201+
}
202+
203+
html.dark pre.astro-code,
204+
html.dark pre.astro-code span {
205+
color: var(--shiki-dark) !important;
206+
background-color: var(--code-bg-dark) !important;
207+
}
208+
175209
/* Copy buttons */
176210
button.copy,
177211
.shiki-copy,
@@ -183,8 +217,8 @@ pre.astro-code > button.copy {
183217
border: none;
184218
border-radius: 4px;
185219
cursor: pointer;
186-
background-color: rgba(255, 255, 255, 0.1);
187-
color: white;
220+
background-color: rgba(0, 0, 0, 0.1);
221+
color: #333;
188222
opacity: 0.5;
189223
z-index: 10;
190224
pointer-events: auto;
@@ -194,6 +228,13 @@ pre.astro-code > button.copy {
194228
background-color 0.2s;
195229
}
196230

231+
html.dark button.copy,
232+
html.dark .shiki-copy,
233+
html.dark pre.astro-code > button.copy {
234+
background-color: rgba(255, 255, 255, 0.1);
235+
color: white;
236+
}
237+
197238
.terminal-code-container button.copy,
198239
.terminal-code-container .shiki-copy,
199240
.terminal-code-container pre.astro-code > button.copy {
@@ -216,13 +257,20 @@ button.copy:hover,
216257
.shiki-copy:hover,
217258
pre.astro-code > button.copy:hover {
218259
opacity: 1;
260+
background-color: rgba(0, 0, 0, 0.2);
261+
}
262+
263+
html.dark button.copy:hover,
264+
html.dark .shiki-copy:hover,
265+
html.dark pre.astro-code > button.copy:hover {
219266
background-color: rgba(255, 255, 255, 0.2);
220267
}
221268

222269
button.copy.copied,
223270
.shiki-copy.copied,
224271
pre.astro-code > button.copy.copied {
225-
background-color: #28a745;
272+
background-color: #0891b2 !important;
273+
color: white !important;
226274
opacity: 1;
227275
}
228276

0 commit comments

Comments
 (0)