From 6ddf3af7b143473e5c41a100ab146fef80dd453f Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Thu, 21 May 2020 11:48:12 +0000
Subject: [PATCH] Proposal for dark theme
---
layouts/partials/navbar.html | 12 +--
assets/js/anatole.js | 37 ++++++++++++
assets/css/style.css | 76 ++++---------------------
README.md | 1
layouts/partials/footer.html | 28 --------
5 files changed, 57 insertions(+), 97 deletions(-)
diff --git a/README.md b/README.md
index be6673d..7b55e26 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@
### Features include:
- Profile picture and slogan
+- Dark mode
- Navigation items
- Pagination
- Google Analytics (optional)
diff --git a/assets/css/style.css b/assets/css/style.css
index 64becf8..460bd52 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -1,6 +1,7 @@
@charset "UTF-8";
:root{
--bg-color:#fff;
+ --secondary-bg-color:#fff;
--heading-color: #5f5f5f;
--body-color: rgba(0, 0, 0, 0.5);
--post-color: rgba(0, 0, 0, 0.44);
@@ -14,14 +15,14 @@
-webkit-font-smoothing: antialiased;
}
html[data-theme='dark'] {
- --bg-color:#222831;
- --secondary-bg-color: #393e46;
- --heading-color: #d65a31;
- --body-color: white;
+ --bg-color:rgb(28, 28, 33);
+ --secondary-bg-color:rgb(28, 28, 33);
+ --heading-color:rgba(191, 191, 191, 0.5);
+ --body-color: rgba(191, 191, 191, 0.5);
--post-color: rgba(0, 0, 0, 0.44);
- --border-color: rgba(0, 0, 0, 0.15);
- --nav-text-color: #fff;
+ --border-color: rgb(38, 38, 38);;
--pre-bg-color: #21212d;
+ --nav-text-color:rgb(191, 191, 191);
--tag-color: rgb(83, 83, 83) !important;
}
@@ -49,7 +50,7 @@
border-radius: 3px;
color: #fff;
background-color: #f9f9fd;
- border: 1px solid #f2f2f2;
+ border: 1px solid var(--border-color);
}
.tag::before {
@@ -175,7 +176,7 @@
z-index: 3;
background-color: var(--secondary-bg-color);
height: 60px;
- border-bottom: 1px solid #f2f2f2;
+ border-bottom: 1px solid var(--border-color);
}
.page-top .nav {
list-style: none;
@@ -199,59 +200,6 @@
padding-bottom: 22px;
border-bottom: 1px solid var(--nav-text-color);
}
-
-.theme-switch {
- display: inline-block;
- height: 34px;
- position: relative;
- width: 60px;
-}
-.theme-switch-wrapper{
-
- float: right;
-
-}
-.theme-switch input {
- display:none;
-}
-
-.slider {
- background-color: #ccc;
- bottom: 0;
- cursor: pointer;
- left: 0;
- position: absolute;
- right: 0;
- top: 0;
- transition: .4s;
-}
-
-.slider:before {
- background-color: #fff;
- bottom: 4px;
- content: "";
- height: 26px;
- left: 4px;
- position: absolute;
- transition: .4s;
- width: 26px;
-}
-
-input:checked + .slider {
- background-color: #66bb6a;
-}
-
-input:checked + .slider:before {
- transform: translateX(26px);
-}
-
-.slider.round {
- border-radius: 34px;
-}
-
-.slider.round:before {
- border-radius: 50%;
-}
.page-top .information {
float: right;
padding-top: 12px;
@@ -286,7 +234,7 @@
left: 0;
position: fixed;
z-index: 4;
- border-right: 1px solid #f2f2f2;
+ border-right: 1px solid var(--border-color);
}
.sidebar .logo-title {
text-align: center;
@@ -396,7 +344,7 @@
}
.post .post-footer {
padding: 0 0 30px 0;
- border-bottom: 1px solid #f2f2f2;
+ border-bottom: 1px solid var(--border-color);
}
.post .post-footer .meta {
max-width: 100%;
@@ -502,7 +450,7 @@
#disqus_thread {
margin: 30px;
- border-bottom: 1px solid #f2f2f2;
+ border-bottom: 1px solid var(--border-color);
}
.footer {
diff --git a/assets/js/anatole.js b/assets/js/anatole.js
new file mode 100644
index 0000000..40a1da0
--- /dev/null
+++ b/assets/js/anatole.js
@@ -0,0 +1,37 @@
+const themeSwitcher = document.querySelector('.theme-switch');
+
+function getTheme(){
+ return localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
+}
+
+// switch themes
+function switchTheme(e) {
+ var theme = getTheme();
+ if (theme == 'light') {
+ document.documentElement.setAttribute('data-theme', 'dark');
+ localStorage.setItem('theme', 'dark');
+ }
+ else {
+ document.documentElement.setAttribute('data-theme', 'light');
+ localStorage.setItem('theme', 'light');
+ }
+}
+
+// initialize default value
+var theme = getTheme();
+if (theme === null) {
+ document.documentElement.setAttribute('data-theme', 'light');
+ localStorage.setItem('theme', 'light');
+}
+else {
+ // load a stored theme
+ if (theme == 'light') {
+ document.documentElement.setAttribute('data-theme', 'light');
+ }
+ else {
+ document.documentElement.setAttribute('data-theme', 'dark');
+ }
+}
+
+
+themeSwitcher.addEventListener('click', switchTheme, false);
\ No newline at end of file
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 64dce74..36b2a41 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -6,36 +6,12 @@
<script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
{{ $migrate := resources.Get "js/jquery-migrate.js" }}
{{ $appear := resources.Get "js/jquery-appear.js" }}
-{{ $js := slice $migrate $appear | resources.Concat "js/bundle.js" }}
+{{ $anatole := resources.Get "js/anatole.js" }}
+{{ $js := slice $migrate $appear $anatole | resources.Concat "js/bundle.js" }}
{{ $secureJS := $js | resources.Minify | resources.Fingerprint }}
<script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
{{- partial "medium-zoom.html" . -}}
{{- partial "math.html" . -}}
{{- template "_internal/google_analytics_async.html" . -}}
-<script type="text/javascript" >
-const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
-
-function switchTheme(e) {
- if (e.target.checked) {
- document.documentElement.setAttribute('data-theme', 'dark');
- localStorage.setItem('theme', 'dark');
- }
- else {
- document.documentElement.setAttribute('data-theme', 'light');
- localStorage.setItem('theme', 'light');
- }
-}
-
-toggleSwitch.addEventListener('change', switchTheme, false);
-const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
-
-if (currentTheme) {
- document.documentElement.setAttribute('data-theme', currentTheme);
-
- if (currentTheme === 'dark') {
- toggleSwitch.checked = true;
- }
-}
-</script>
</html>
\ No newline at end of file
diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html
index 0fcaeee..146bbaf 100644
--- a/layouts/partials/navbar.html
+++ b/layouts/partials/navbar.html
@@ -5,12 +5,10 @@
<li><a {{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}class="current"{{end}} href="{{ .URL }}" title="{{ .Title }}">{{ .Name }}</a></li>
{{ end }}
- <div class="theme-switch-wrapper">
- <label class="theme-switch" for="checkbox">
- <input type="checkbox" id="checkbox" />
- <div class="slider round"></div>
- </label>
-
- </div>
+ <li>
+ <a class="theme-switch" title="Switch Theme">
+ <i class="fa fa-adjust fa-fw" aria-hidden="true"></i>
+ </a>
+ </li>
</div>
</div>
\ No newline at end of file
--
Gitblit v1.10.0