summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanxiaobei <nanxiaobei@gmail.com>2019-10-15 01:31:07 +0800
committernanxiaobei <nanxiaobei@gmail.com>2019-10-15 01:31:07 +0800
commitba297661ff44f2e60c96f0640a4c4d23760826df (patch)
tree4d61637a5b3fb97e20b4b47065d63a39ff998802
parent072d2a8c22bc45391a27826b95ee3b811422c3e9 (diff)
Add dark mode
-rw-r--r--layouts/partials/header.html3
-rw-r--r--static/main.js35
-rw-r--r--static/style.css44
3 files changed, 37 insertions, 45 deletions
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index f79c35c..5d04a26 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -38,9 +38,6 @@
{{ end }}
</head>
<body class="{{if eq .Kind `page` }}single{{else}}list{{ if .IsHome }} home{{ end }}{{end}}">
- {{if ne .Kind `page` }}
- <div class="list-bg"></div>
- {{end}}
<header class="header">
<nav class="nav">
{{ if .IsHome }}
diff --git a/static/main.js b/static/main.js
index 10d8fe1..dfef446 100644
--- a/static/main.js
+++ b/static/main.js
@@ -1,24 +1,17 @@
+// Highlight
hljs.initHighlightingOnLoad();
-const listBg = document.querySelector('.list-bg');
-
-if (listBg) {
- const halfAnHour = 1000 * 60 * 30;
-
- function setListBgStyle() {
- const now = new Date();
- const time = now.getHours() + now.getMinutes() / 60;
-
- let opacity = Math.abs(time - 14);
- opacity = opacity > 12 ? 10 + Math.abs(opacity - 14) : opacity;
- opacity = Number((opacity / 12).toFixed(2));
-
- listBg.setAttribute('style', `opacity: ${opacity}`);
+// SunriseSunset
+const getSunrise = SunriseSunsetJS.getSunrise;
+const getSunset = SunriseSunsetJS.getSunset;
+navigator.geolocation.getCurrentPosition((position) => {
+ const latitude = position.coords.latitude;
+ const longitude = position.coords.longitude;
+ const sunrise = getSunrise(latitude, longitude).getTime();
+ const sunset = getSunset(latitude, longitude).getTime();
+ const now = Date.now();
+ if (now < sunrise || now < sunset) {
+ const body = document.querySelector('body');
+ body.classList.add('dark');
}
-
- requestAnimationFrame(setListBgStyle);
-
- setInterval(() => {
- requestAnimationFrame(setListBgStyle);
- }, halfAnHour);
-}
+});
diff --git a/static/style.css b/static/style.css
index f61700b..012be40 100644
--- a/static/style.css
+++ b/static/style.css
@@ -3,10 +3,10 @@
* A simple, clean, flexible Hugo theme
* https://github.com/nanxiaobei/hugo-paper
* Designed by MR.LEE (https://mrlee.me/)
- * Updated in 2019.9.15
+ * Updated in 2019.10.15
*/
-/* Variables
+/* Theme
-------------------------------------------------- */
:root {
--gap: 24px;
@@ -17,6 +17,7 @@
--footer-height: 60px;
--radius: 8px;
+ --theme: #fff;
--primary: rgba(0, 0, 0, 0.88);
--secondary: rgba(0, 0, 0, 0.56);
--tertiary: rgba(0, 0, 0, 0.16);
@@ -25,6 +26,22 @@
--code-bg: #f5f5f5;
--border: #eee;
}
+.dark {
+ --theme: #3c3c3c;
+ --primary: rgba(255, 255, 255, 0.88);
+ --secondary: rgba(255, 255, 255, 0.56);
+ --tertiary: rgba(255, 255, 255, 0.16);
+
+ --hljs-bg: #2a2a2a;
+ --code-bg: #4f4f4f;
+ --border: #5f5f5f;
+}
+.list {
+ background: linear-gradient(135deg, #e2e2e2, #f8f8f8, #ddd);
+}
+.dark.list {
+ background: linear-gradient(135deg, #1c1c1c, #2a2a2a, #000);
+}
/* Reset
-------------------------------------------------- */
*,
@@ -43,6 +60,7 @@ body {
font-size: 18px;
line-height: 1.8;
word-break: break-word;
+ background: var(--theme);
}
article,
aside,
@@ -112,7 +130,7 @@ textarea {
}
input:-webkit-autofill,
textarea:-webkit-autofill {
- box-shadow: 0 0 0 50px #fff inset;
+ box-shadow: 0 0 0 50px var(--theme) inset;
}
img {
display: block;
@@ -153,22 +171,6 @@ img {
.menu a {
font-size: 16px;
}
-/* Body
--------------------------------------------------- */
-.list {
- position: relative;
- background: linear-gradient(135deg, #e2e2e2, #f8f8f8, #ddd);
-}
-.list-bg {
- position: absolute;
- z-index: -1;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- background: rgba(0, 0, 0, 0.24);
- opacity: 0;
-}
/* Main
-------------------------------------------------- */
.main {
@@ -189,7 +191,7 @@ img {
display: flex;
}
.pagination a {
- color: #fff;
+ color: var(--theme);
font-size: 13px;
line-height: 36px;
background: var(--primary);
@@ -236,7 +238,7 @@ img {
position: relative;
margin-bottom: var(--gap);
padding: var(--gap);
- background: #fff;
+ background: var(--theme);
border-radius: var(--radius);
transition: transform 0.1s;
}