tangled
alpha
login
or
join now
lesbian.skin
/
website
1
fork
atom
My website
lesbian.skin
1
fork
atom
overview
issues
pulls
pipelines
Add dark mode
lesbian.skin
2 years ago
4dca9756
d0abce59
+50
-1
3 changed files
expand all
collapse all
unified
split
src
input.css
static
script.js
website
common.gleam
+1
src/input.css
···
11
11
"CASL" 0,
12
12
"CRSV" 0.5,
13
13
"MONO" 0;
14
14
+
transition-duration: 750ms;
14
15
}
+33
src/static/script.js
···
1
1
+
function setDarkMode(dark, preference) {
2
2
+
if (dark) {
3
3
+
preference !== "dark"
4
4
+
? localStorage.setItem("theme", "dark")
5
5
+
: localStorage.removeItem("theme");
6
6
+
document.documentElement.classList.add("dark");
7
7
+
} else if (!dark) {
8
8
+
preference !== "light"
9
9
+
? localStorage.setItem("theme", "light")
10
10
+
: localStorage.removeItem("theme");
11
11
+
document.documentElement.classList.remove("dark");
12
12
+
}
13
13
+
}
14
14
+
15
15
+
const preference = window.matchMedia("(prefers-color-scheme: dark)").matches
16
16
+
? "dark"
17
17
+
: "light";
18
18
+
if (
19
19
+
localStorage.getItem("theme") === "dark" ||
20
20
+
(!("theme" in localStorage) && preference === "dark")
21
21
+
) {
22
22
+
setDarkMode(true, preference);
23
23
+
}
24
24
+
window.onload = function () {
25
25
+
document
26
26
+
.getElementById("button-dark-mode")
27
27
+
.addEventListener("click", function () {
28
28
+
setDarkMode(
29
29
+
!document.documentElement.classList.contains("dark"),
30
30
+
preference,
31
31
+
);
32
32
+
});
33
33
+
};
+16
-1
src/website/common.gleam
···
40
40
html.html([attr.attribute("lang", "en")], [
41
41
html.head([], [
42
42
html.meta([attr.attribute("charset", "UTF-8")]),
43
43
+
html.script([attr.src("/script.js")], ""),
43
44
html.link([attr.rel("stylesheet"), attr.href("/style.css")]),
44
45
html.link([
45
46
attr.rel("preconnect"),
···
62
63
html.body(
63
64
[
64
65
attr.class(
65
65
-
"my-0 sm:my-5 mx-0 sm:mx-6 md:mx-10 lg:mx-20 xl:mx-48 2xl:mx-64",
66
66
+
"my-0 sm:my-5 mx-0 sm:mx-6 md:mx-10 lg:mx-20 xl:mx-48 2xl:mx-64 dark:bg-neutral-700",
66
67
),
67
68
],
68
69
[navbar(), ..elements],
···
97
98
navitem(name: "Home", href: ""),
98
99
navitem(name: "Projects", href: "projects"),
99
100
navitem(name: "Posts", href: "posts"),
101
101
+
darkmode(),
100
102
],
103
103
+
)
104
104
+
}
105
105
+
106
106
+
fn darkmode() -> element.Element(e) {
107
107
+
html.button(
108
108
+
[
109
109
+
attr.id("button-dark-mode"),
110
110
+
attr.class(
111
111
+
"drop-shadow-md no-underline bg-gray-300 dark:bg-neutral-900 p-3 rounded-xl text-black dark:text-neutral-200
112
112
+
before:content-['☀️'] dark:before:content-['🌕️']",
113
113
+
),
114
114
+
],
115
115
+
[],
101
116
)
102
117
}
103
118