-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ site | |
static/styles/vendor.css | ||
static/styles/app.css | ||
static/styles/fonts.css | ||
static/styles/noscript.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This stylesheet is used when the user agent has no JavaScript capabilities (or has it disabled) | ||
// Sets dark theme according to user agent preferences | ||
|
||
// Default light theme | ||
:root, :root:not([data-theme]) { | ||
--gray: #2a3439; | ||
--red: #a72145; | ||
--yellow: #ffc832; | ||
--code-color: black; | ||
--code-bg-color: rgba(42, 52, 57, 0.05); | ||
--code-border-color: rgba(42, 52, 57, 0.25); | ||
--blockquote-color: black; | ||
--blockquote-bg-color: rgb(247, 249, 249); | ||
--blockquote-left-border-color: rgb(195, 205, 210); | ||
--body-background-color: white; | ||
--body-foreground-color: white; | ||
--body-color: rgb(34,34,34); | ||
--div-brand-a-color: black; | ||
--white-elem-color: black; | ||
--white-a: #2a3439; | ||
--nav-links-a: #2a3439; | ||
--publish-date-author: #2a3439; | ||
--section-header-h2-color: black; | ||
} | ||
|
||
// Dark theme (probed from user prefs) | ||
@media (prefers-color-scheme: dark) { | ||
:root, :root:not([data-theme]) { | ||
--gray: #2a3439; | ||
--red: #a72145; | ||
--yellow: #ffc832; | ||
--code-color: white; | ||
--code-bg-color: rgba(213, 203, 198, 0.05); | ||
--code-border-color: rgba(213, 203, 198, 0.25); | ||
--blockquote-color: rgb(195, 205, 210); | ||
--blockquote-bg-color: rgba(213, 203, 198, 0.05); | ||
--blockquote-left-border-color: rgb(195, 205, 210); | ||
--body-background-color: #181a1b; | ||
--body-foreground-color: #e8e6e3; | ||
--body-color: white; | ||
--div-brand-a-color: white; | ||
--white-elem-color: white; | ||
--white-elem-a: #d5cbc6; | ||
--nav-links-a: #d5cbc6; | ||
--publish-date-author: #d5cbc6; | ||
--section-header-h2-color: white; | ||
} | ||
} | ||
|
||
// Don't show the theme selector button when JavaScript is disabled | ||
#theme-icon { | ||
display: none !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function changeThemeTo(val) { | ||
document.documentElement.setAttribute("data-theme", val); | ||
// save theme prefs in the browser | ||
if (storageAvailable("localStorage")) { | ||
localStorage.setItem("blog-rust-lang-org-theme", val); | ||
} | ||
// the theme dropdown will close itself when returning to the dropdown() caller | ||
} | ||
|
||
function dropdown () { | ||
document.getElementById("theme-choice").classList.toggle("showThemeDropdown"); | ||
} | ||
|
||
// courtesy MDN | ||
function storageAvailable(type) { | ||
let storage; | ||
try { | ||
storage = window[type]; | ||
const x = "__storage_test__"; | ||
storage.setItem(x, x); | ||
storage.removeItem(x); | ||
return true; | ||
} catch (e) { | ||
return ( | ||
e instanceof DOMException && | ||
e.name === "QuotaExceededError" && | ||
// acknowledge QuotaExceededError only if there's something already stored | ||
storage && | ||
storage.length !== 0 | ||
); | ||
} | ||
} | ||
|
||
|
||
// Check for saved user preference on load, else check and save user agent prefs | ||
let savedTheme = null; | ||
if (storageAvailable("localStorage")) { | ||
savedTheme = localStorage.getItem("blog-rust-lang-org-theme"); | ||
} | ||
if (savedTheme) { | ||
document.documentElement.setAttribute("data-theme", savedTheme); | ||
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
document.documentElement.setAttribute("data-theme", "dark"); | ||
localStorage.setItem("blog-rust-lang-org-theme", "dark"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters