Skip to content

Automatic dark mode #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ enableGitInfo = true
theme = "book"

[params]
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme = 'auto'

# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
BookRepo = 'https://github.com/xsleaks/wiki'
Expand Down
7 changes: 5 additions & 2 deletions themes/book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ enableGitInfo = true
disableKinds = ['taxonomy', 'taxonomyTerm']

[params]
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme = 'light'

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down Expand Up @@ -251,11 +255,10 @@ There are few features implemented as plugable `scss` styles. Usually this are f

| Plugin | Description |
| --------------------------------- | ----------------------------------------------------------- |
| `assets/plugins/_dark.scss` | Switches site to dark mode |
| `assets/plugins/_numbered.scss` | Makes headings in markdown numbered, e.g. `1.1`, `1.2` |
| `assets/plugins/_scrollbars.scss` | Overrides scrollbar styles to look similar across platforms |

To enable plugin add `@import "plugins/{name}";` to `assets/_custom.scss` in your website root. Exception is `_dark.scss` which contains only variables and should be added to `assets/_variables.scss`.
To enable plugins, add `@import "plugins/{name}";` to `assets/_custom.scss` in your website root.

### Hugo Internal Templates

Expand Down
55 changes: 36 additions & 19 deletions themes/book/assets/_defaults.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ $font-size-16: 1rem !default;

$border-radius: $padding-4 !default;

// Grayscale
$white: #ffffff !default;
$gray-100: #f8f9fa !default;
$gray-200: #e9ecef !default;
$gray-300: #dee2e6 !default;
$gray-400: #ced4da !default;
$gray-500: #adb5bd !default;
$gray-600: #868e96 !default;
$gray-700: #495057 !default;
$gray-800: #343a40 !default;
$gray-900: #212529 !default;
$black: #000 !default;

$color-link: #05b !default;
$color-visited-link: #8440f1 !default;

$body-background: white !default;
$body-font-color: $black !default;
$body-font-weight: normal !default;

$body-min-width: 20rem !default;
Expand All @@ -49,4 +31,39 @@ $hint-colors: (
good: #004D40
) !default;

$icon-filter: none !default;
// Themes
@mixin theme-light {
--gray-100: #f8f9fa;
--gray-200: #e9ecef;
--gray-500: #adb5bd;

--color-link: #0055bb;
--color-visited-link: #8440f1;

--body-background: white;
--body-font-color: black;

--icon-filter: none;

--hint-color-info: #6bf;
--hint-color-warning: #fd6;
--hint-color-danger: #f66;
}

@mixin theme-dark {
--gray-100: rgba(255, 255, 255, 0.1);
--gray-200: rgba(255, 255, 255, 0.2);
--gray-500: rgba(255, 255, 255, 0.5);

--color-link: #84b2ff;
--color-visited-link: #b88dff;

--body-background: #343a40;
--body-font-color: #e9ecef;

--icon-filter: brightness(0) invert(1);

--hint-color-info: #6bf;
--hint-color-warning: #fd6;
--hint-color-danger: #f66;
}
20 changes: 10 additions & 10 deletions themes/book/assets/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ html {

body {
min-width: $body-min-width;
color: $body-font-color;
background: $body-background;
color: var(--body-font-color);
background: var(--body-background);

letter-spacing: 0.33px;
font-weight: $body-font-weight;
Expand All @@ -31,7 +31,7 @@ h5 {

a {
text-decoration: none;
color: $color-link;
color: var(--color-link);
}

img {
Expand Down Expand Up @@ -81,7 +81,7 @@ ul.pagination {
}

.book-icon {
filter: $icon-filter;
filter: var(--icon-filter);
}

.book-brand {
Expand All @@ -102,7 +102,7 @@ ul.pagination {
nav {
width: $menu-width;
padding: $padding-16;
background: $body-background;
background: var(--body-background);

@include fixed;
}
Expand All @@ -113,7 +113,7 @@ ul.pagination {
}

a.active {
color: $color-link;
color: var(--color-link);
}

a.collapsed {
Expand Down Expand Up @@ -174,8 +174,8 @@ ul.pagination {
border: 0;
border-radius: $border-radius;

background: $gray-100;
color: $body-font-color;
background: var(--gray-100);
color: var(--body-font-color);

&:required + .book-search-spinner {
display: block;
Expand All @@ -192,7 +192,7 @@ ul.pagination {
height: $padding-16;

border: $padding-1 solid transparent;
border-top-color: $body-font-color;
border-top-color: var(--body-font-color);
border-radius: 50%;

@include spin(1s);
Expand Down Expand Up @@ -271,7 +271,7 @@ ul.pagination {
left: 0;
padding: $padding-8 0;

background: $body-background;
background: var(--body-background);
box-shadow: 0 0 $padding-4 rgba(0, 0, 0, 0.1);

li img {
Expand Down
21 changes: 11 additions & 10 deletions themes/book/assets/_markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

a.anchor {
opacity: 0;
font-size: .75em;
font-size: 0.75em;
vertical-align: middle;
text-decoration: none;
}

&:hover a.anchor, a.anchor:focus {
&:hover a.anchor,
a.anchor:focus {
opacity: initial;
}
}
Expand All @@ -52,7 +53,7 @@
text-decoration: underline;
}
&:visited {
color: $color-visited-link;
color: var(--color-visited-link);
}
}

Expand All @@ -62,14 +63,14 @@

code {
padding: 0 $padding-4;
background: $gray-200;
background: var(--gray-200);
border-radius: $border-radius;
font-size: 0.875em;
}

pre {
padding: $padding-16;
background: $gray-100;
background: var(--gray-100);
border-radius: $border-radius;
overflow-x: auto;

Expand All @@ -83,7 +84,7 @@
margin: $padding-16 0;
padding: $padding-8 $padding-16 $padding-8 ($padding-16 - $padding-4); //to keep total left space 16dp

border-inline-start: $padding-4 solid $gray-200;
border-inline-start: $padding-4 solid var(--gray-200);
border-radius: $border-radius;

:first-child {
Expand All @@ -105,18 +106,18 @@
tr th,
tr td {
padding: $padding-8 $padding-16;
border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
}

tr:nth-child(2n) {
background: $gray-100;
background: var(--gray-100);
}
}

hr {
height: $padding-1;
border: none;
background: $gray-200;
background: var(--gray-200);
}

ul,
Expand Down Expand Up @@ -150,7 +151,7 @@

details {
padding: $padding-16;
border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

summary {
Expand Down
16 changes: 8 additions & 8 deletions themes/book/assets/_shortcodes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
margin-top: $padding-16;
margin-bottom: $padding-16;

border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

overflow: hidden;

.book-expand-head {
background: $gray-100;
background: var(--gray-100);
padding: $padding-8 $padding-16;
cursor: pointer;
}
Expand All @@ -30,7 +30,7 @@
margin-top: $padding-16;
margin-bottom: $padding-16;

border: $padding-1 solid $gray-200;
border: $padding-1 solid var(--gray-200);
border-radius: $border-radius;

overflow: hidden;
Expand All @@ -48,19 +48,19 @@
.book-tabs-content {
order: 999; //Move content blocks to the end
width: 100%;
border-top: $padding-1 solid $gray-100;
border-top: $padding-1 solid var(--gray-100);
padding: $padding-16;
display: none;
}

input[type="radio"]:checked + label {
border-bottom: $padding-1 solid $color-link;
border-bottom: $padding-1 solid var(--color-link);
}
input[type="radio"]:checked + label + .book-tabs-content {
display: block;
}
input[type="radio"]:focus + label {
@include outline
@include outline;
}
}

Expand All @@ -80,10 +80,10 @@
a.book-btn {
display: inline-block;
font-size: $font-size-14;
color: $color-link;
color: var(--color-link);
line-height: $padding-16 * 2;
padding: 0 $padding-16;
border: $padding-1 solid $color-link;
border: $padding-1 solid var(--color-link);
border-radius: $border-radius;
cursor: pointer;

Expand Down
1 change: 1 addition & 0 deletions themes/book/assets/book.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "defaults";
@import "variables";
@import "themes/{{ default "light" .Site.Params.BookTheme }}";

@import "normalize";
@import "utils";
Expand Down
10 changes: 0 additions & 10 deletions themes/book/assets/plugins/_dark.scss

This file was deleted.

6 changes: 3 additions & 3 deletions themes/book/assets/plugins/_scrollbars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
}

:hover::-webkit-scrollbar-thumb {
background: $gray-500;
background: var(--gray-500);
}

// MS
body {
-ms-overflow-style: -ms-autohiding-scrollbar
-ms-overflow-style: -ms-autohiding-scrollbar;
}

// Future
.book-menu nav {
scrollbar-color: transparent $gray-500;
scrollbar-color: transparent var(--gray-500);
}
9 changes: 9 additions & 0 deletions themes/book/assets/themes/_auto.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:root {
@include theme-light;
}

@media (prefers-color-scheme: dark) {
:root {
@include theme-dark;
}
}
3 changes: 3 additions & 0 deletions themes/book/assets/themes/_dark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
@include theme-dark;
}
3 changes: 3 additions & 0 deletions themes/book/assets/themes/_light.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
@include theme-light;
}
4 changes: 4 additions & 0 deletions themes/book/exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enableGitInfo = true
weight = 20

[params]
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme = 'light'

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down
4 changes: 4 additions & 0 deletions themes/book/exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ menu:
weight: 20

params:
# (Optional, default light) Sets color theme: light, dark or auto.
# Theme 'auto' switches between dark and light modes based on browser/os preferences
BookTheme: "light"

# (Optional, default true) Controls table of contents visibility on right side of pages.
# Start and end levels can be controlled with markup.tableOfContents setting.
# You can also specify this parameter per page in front matter.
Expand Down
Loading