Skip to content

Commit

Permalink
Automatic dark/light colorschemes (#234)
Browse files Browse the repository at this point in the history
* Automatic dark/light colorschemes

A new `colorscheme` option is added with the capability to be always dark,
always light, or automatic based on the user's browser setting.  This
makes the `inverted` option superfluous, and therefore deprecated.
Nomenclature of files, variables, etc are changed from `inverted` to
`dark` to reflect this change.

Closes #226.

* Remove inverted option completely

The `inverted` option is now not just deprecated, but removed
completely.
  • Loading branch information
thesmiley1 authored and luizdepra committed Nov 21, 2019
1 parent f6caaf0 commit b00b750
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 116 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@
- [Ariejan de Vroom](https://www.devroom.io) - [Ariejan de Vroom](https://www.devroom.io)
- [Bobby Lindsey](https://bobbywlindsey.com) - [Bobby Lindsey](https://bobbywlindsey.com)
- [José Mª Escartín](https://github.com/jme52) - [José Mª Escartín](https://github.com/jme52)
- [John Schroeder](https://blog.schroedernet.software)
49 changes: 49 additions & 0 deletions assets/scss/_base_dark.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
@mixin base_dark {

color: $fg-color-dark;
background-color: $bg-color-dark;

a {
color: $link-color-dark;
}

h1,
h2,
h3,
h4,
h5,
h6 {
color: $alt-fg-color-dark;
}

code {
background-color: $alt-bg-color-dark;
color: $fg-color-dark;
}

pre {
code {
background-color: inherit;
color: inherit;
}
}

blockquote {
border-left: 2px solid $alt-bg-color-dark;
}

table td, table th {
border: 2px solid $alt-fg-color-dark;
}

}

body.colorscheme-dark {
@include base_dark()
}

body.colorscheme-auto {
@media (prefers-color-scheme: dark) {
@include base_dark()
}
}
39 changes: 0 additions & 39 deletions assets/scss/_base_inverted.scss

This file was deleted.

Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,15 @@
body.inverted { @mixin content_dark {


.content { .content {


.list { .list {
ul { ul {
li { li {
.title { .title {
color: $fg-color-inverted; color: $fg-color-dark;
&:hover, &:hover,
&:focus { &:focus {
color: $link-color-inverted color: $link-color-dark;
} }
} }
} }
Expand All @@ -21,10 +21,10 @@ body.inverted {
ul { ul {
li { li {
a { a {
color: $fg-color-inverted; color: $fg-color-dark;
&:hover, &:hover,
&:focus { &:focus {
color: $link-color-inverted; color: $link-color-dark;
} }
} }
} }
Expand All @@ -34,3 +34,13 @@ body.inverted {
} }


} }

body.colorscheme-dark {
@include content_dark()
}

body.colorscheme-auto {
@media (prefers-color-scheme: dark) {
@include content_dark()
}
}
17 changes: 17 additions & 0 deletions assets/scss/_footer_dark.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
@mixin footer_dark {
.footer {
a {
color: $link-color-dark;
}
}
}

body.colorscheme-dark {
@include footer_dark()
}

body.colorscheme-auto {
@media (prefers-color-scheme: dark) {
@include footer_dark()
}
}
7 changes: 0 additions & 7 deletions assets/scss/_footer_inverted.scss

This file was deleted.

54 changes: 54 additions & 0 deletions assets/scss/_navigation_dark.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,54 @@
@mixin navigation_dark {


.navigation {
a, span {
color: $fg-color-dark;
}
a {
&:hover,
&:focus {
color: $link-color-dark;
}
}
.navigation-list {
@media only screen and (max-width : 768px) {
background-color: $bg-color-dark;
border-top: solid 2px $alt-bg-color-dark;
border-bottom: solid 2px $alt-bg-color-dark;
}
.menu-separator {
@media only screen and (max-width : 768px) {
border-top: 2px solid $fg-color-dark;
}
}
}
#menu-toggle {
@media only screen and (max-width : 768px) {
&:checked + label {
color: $alt-bg-color-dark;
}
}
}
.menu-button {
@media only screen and (max-width : 768px) {
color: $fg-color-dark;
&:hover,
&:focus {
color: $link-color-dark;
}
}
}
}

}

body.colorscheme-dark {
@include navigation_dark()
}

body.colorscheme-auto {
@media (prefers-color-scheme: dark) {
@include navigation_dark()
}
}
44 changes: 0 additions & 44 deletions assets/scss/_navigation_inverted.scss

This file was deleted.

12 changes: 6 additions & 6 deletions assets/scss/_variables.scss
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ $alt-bg-color: #E0E0E0 !default;
$alt-fg-color: #000 !default; $alt-fg-color: #000 !default;
$link-color: #1565c0 !default; $link-color: #1565c0 !default;


// Colors inverted // Colors dark
$bg-color-inverted: #212121 !default; $bg-color-dark: #212121 !default;
$fg-color-inverted: #dadada !default; $fg-color-dark: #dadada !default;
$alt-bg-color-inverted: #424242 !default; $alt-bg-color-dark: #424242 !default;
$alt-fg-color-inverted: #dadada !default; $alt-fg-color-dark: #dadada !default;
$link-color-inverted: #36679f !default; $link-color-dark: #36679f !default;
5 changes: 5 additions & 0 deletions assets/scss/coder-dark.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "variables";
@import "base_dark";
@import "content_dark";
@import "navigation_dark";
@import "footer_dark";
5 changes: 0 additions & 5 deletions assets/scss/coder-inverted.scss

This file was deleted.

8 changes: 6 additions & 2 deletions exampleSite/config.toml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ disqusShortname = "yourdiscussshortname"


rtl = false rtl = false


# Use inverted colors # Specify light/dark colorscheme
inverted = false # Supported values:
# "auto" (use preference set by browser)
# "dark" (dark background, light foreground)
# "light" (light background, dark foreground) (default)
colorscheme = "light"


# Series see also post count # Series see also post count
maxSeeAlsoItems = 5 maxSeeAlsoItems = 5
Expand Down
18 changes: 12 additions & 6 deletions layouts/_default/baseof.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
{{ end }} {{ end }}
{{ end }} {{ end }}


{{ if .Site.Params.inverted }} {{ if or (eq .Site.Params.colorscheme "auto") (eq .Site.Params.colorscheme "dark") }}
{{ if .Site.IsServer }} {{ if .Site.IsServer }}
{{ $cssOpts := (dict "targetPath" "css/coder-inverted.css" "enableSourceMap" true ) }} {{ $cssOpts := (dict "targetPath" "css/coder-dark.css" "enableSourceMap" true ) }}
{{ $styles := resources.Get "scss/coder-inverted.scss" | resources.ExecuteAsTemplate "style.coder-inverted.css" . | toCSS $cssOpts }} {{ $styles := resources.Get "scss/coder-dark.scss" | resources.ExecuteAsTemplate "style.coder-dark.css" . | toCSS $cssOpts }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" media="screen"> <link rel="stylesheet" href="{{ $styles.RelPermalink }}" media="screen">
{{ else }} {{ else }}
{{ $cssOpts := (dict "targetPath" "css/coder-inverted.css" ) }} {{ $cssOpts := (dict "targetPath" "css/coder-dark.css" ) }}
{{ $styles := resources.Get "scss/coder-inverted.scss" | resources.ExecuteAsTemplate "style.coder-inverted.css" . | toCSS $cssOpts | minify | fingerprint }} {{ $styles := resources.Get "scss/coder-dark.scss" | resources.ExecuteAsTemplate "style.coder-dark.css" . | toCSS $cssOpts | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Integrity }}" crossorigin="anonymous" media="screen" /> <link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Integrity }}" crossorigin="anonymous" media="screen" />
{{ end }} {{ end }}
{{ end }} {{ end }}
Expand All @@ -77,7 +77,13 @@
{{ hugo.Generator }} {{ hugo.Generator }}
</head> </head>


<body class="{{ if .Site.Params.rtl }}rtl{{ end }} {{ if .Site.Params.inverted }}inverted{{ end }}"> {{ $csClass := "colorscheme-light" }}
{{ if eq .Site.Params.colorscheme "dark" }}
{{ $csClass = "colorscheme-dark" }}
{{ else if eq .Site.Params.colorscheme "auto" }}
{{ $csClass = "colorscheme-auto" }}
{{ end }}
<body class="{{ $csClass }}{{ if .Site.Params.rtl }} rtl{{ end }}">
<main class="wrapper"> <main class="wrapper">
{{ partial "header.html" . }} {{ partial "header.html" . }}


Expand Down
4 changes: 2 additions & 2 deletions stackbit.yaml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ models:
name: commit name: commit
- type: boolean - type: boolean
name: rtl name: rtl
- type: boolean - type: string
name: inverted name: colorscheme
- type: number - type: number
name: maxSeeAlsoItems name: maxSeeAlsoItems
- type: list - type: list
Expand Down

0 comments on commit b00b750

Please sign in to comment.