Implement optional dark mode for the documentation site#230
Conversation
Fixed in 4e3c1f4 (see latest commit on the branch):
Verified with a local Hugo build + browser check in both modes.
Correction: the commit is |
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in light/dark theme toggle to the Drasi documentation site using Docsy/Bootstrap’s built-in color modes, while preserving the site’s always-dark Dracula code-block styling. It updates configuration, early theme initialization (to prevent FOUC), and introduces dark-mode-specific styling overrides for Drasi’s custom components.
Changes:
- Enable Docsy’s navbar theme toggle and force “light” as the default unless the visitor explicitly chooses otherwise.
- Add a Docsy/Bootstrap-derived
dark-mode.jsoverride and ensure the<html>element participates in Docsy’s theme initialization flow. - Introduce dark-mode SCSS adjustments for headings, cards, navigation accents, muted text, and specific custom components (e.g., flow-step boxes), plus theme-variable usage in the
scrollable-codeshortcode.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/layouts/shortcodes/scrollable-code.html | Uses Bootstrap CSS variables for theme-aware border/background in the shortcode container. |
| docs/layouts/partials/hooks/head-end.html | Adds an early inline script to default to light theme when no stored preference exists (FOUC mitigation). |
| docs/layouts/docs/baseof.html | Adds Docsy theme-init attribute gating (but currently uses partialCached incorrectly). |
| docs/config.toml | Enables Docsy’s light/dark/auto toggle menu in the navbar. |
| docs/assets/scss/_variables_project.scss | Sets the dark-mode primary lighten amount used by Docsy dark adjustments. |
| docs/assets/scss/_styles_project.scss | Imports Docsy dark color adjustments and adds extensive [data-bs-theme="dark"] overrides for custom components. |
| docs/assets/js/dark-mode.js | Adds a Docsy-adapted Bootstrap color-mode toggler that defaults to light mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixed in I updated dark-mode styling for |



Adds an optional light/dark theme toggle to the docs site. Builds on the approach from #229 but uses Docsy v0.13.0's built-in dark mode (no theme upgrade required — the submodule is already on v0.13.0), and preserves Drasi's distinctive always-dark code blocks. Light mode is the default; dark mode is opt-in via the navbar toggle.
Changes
showLightDarkModeMenu = trueinconfig.tomlsurfaces the navbar light/dark/auto switch.docs/assets/js/dark-mode.jsmakeslightthe default theme, and an early inline script in thehead-end.htmlhook forces light before paint when no preference is stored. The OSprefers-color-schemeis intentionally ignored for the default (it's only honoured when the visitor explicitly picks "auto"). Both spots are needed because Docsy v0.13 otherwise falls back to the OS preference in both the deferred JS and the inline FOUC script.docs/baseof.htmlwas missing Docsy'sdata-theme-initon<html>; added it to mirror upstream and avoid a flash of the wrong theme on load.$lighten-amount-for-dark-color-variant: 30%plus an import of Docsy'std/color-adjustments-dark, so the deep-navy$primaryis legible as links/accents on a dark canvas.[data-bs-theme="dark"]block overrides the ~35 Drasi components that hard-code$primaryas a foreground colour (card/content titles, the hero/h1gradient,h3-based card titles, nav accents, CTA buttons, learning-path/blockquote surfaces, related-content links).$gray-600/$gray-700) used for section intros, captions, taglines and descriptions are lightened to$gray-400/$gray-300so they stay legible on the dark canvas..flow-stepboxes (also used on the Drasi Server getting started page) used a deep-navy border that disappeared on dark; in dark mode they now get an elevated surface, a visible border and a shadow.scrollable-code.htmlcontainer swaps hard-coded light colours forvar(--bs-border-color)/var(--bs-tertiary-bg).Preserved style choices
td/code-darkis intentionally not imported.:not([class*="unified-card--"]).Notes for reviewers
The h3 fix is the non-obvious one: Diátaxis card titles render as
<h3 class="unified-card-title">, and.td-content h3 { color: darken($primary,5%) }out-specifies the--bs-heading-colorvariable — so the dark block targets.td-content h3directly rather than relying on the heading-colour var alone.