Skip to content

Commit

Permalink
✨ feat: allow setting the default theme
Browse files Browse the repository at this point in the history
Used as fallback when JS is disabled and `theme_switcher` is enabled.

If `default_theme` is unset, it defaults to "light".

Used as single theme when `theme_switcher` is disabled.
  • Loading branch information
welpo committed Aug 7, 2023
1 parent ab879e3 commit c78c7f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 9 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,17 @@ language_name.ca = "Català"
language_name.en = "English"
language_name.es = "Español"

# Enable JavaScript theme toggler for dark/light mode (and automatic switching).
# The default setting is the light theme.
# Enable JavaScript theme toggler to allow users to switch between dark/light mode.
# Also enables automatic switching based on user's OS-level theme settings.
# If disabled, your site will only use the theme specified in the `default_theme` variable.
theme_switcher = true

# This setting determines the default theme ("light" or "dark").
# If you wish to use only a dark or light theme, disable the `theme_switcher` above and set this variable.
# If `theme_switcher` is enabled, this will be the theme that is visible to users who have JavaScript disabled.
# Defaults to "light", if unset.
default_theme = "light"

# Add a "copy" button to codeblocks (loads ~700 bytes of JavaScript).
copy_button = true

Expand Down
5 changes: 4 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
{% import "macros/add_comments.html" as macros_add_comments %}

<!DOCTYPE html>
<html lang="{{ lang }}">
<html lang="{{ lang }}" {% if config.extra.default_theme -%}
data-theme="{{config.extra.default_theme}}"
{%- endif -%}>

{% include "partials/header.html" %}

<body>
Expand Down
11 changes: 9 additions & 2 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ language_name.ca = "Català"
language_name.en = "English"
language_name.es = "Español"

# Enable JavaScript theme toggler for dark/light mode (and automatic switching).
# The default setting is the light theme.
# Enable JavaScript theme toggler to allow users to switch between dark/light mode.
# Also enables automatic switching based on user's OS-level theme settings.
# If disabled, your site will only use the theme specified in the `default_theme` variable.
theme_switcher = true

# This setting determines the default theme ("light" or "dark").
# If you wish to use only a dark or light theme, disable the `theme_switcher` above and set this variable.
# If `theme_switcher` is enabled, this will be the theme that is visible to users who have JavaScript disabled.
# Defaults to "light", if unset.
default_theme = "light"

# Add a "copy" button to codeblocks (loads ~700 bytes of JavaScript).
copy_button = true

Expand Down

0 comments on commit c78c7f5

Please sign in to comment.