-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
151 lines (135 loc) · 5.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dipam's Notebook</title>
<link rel="stylesheet" href="style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Azeret+Mono:ital,wght@0,100..900;1,100..900&family=Figtree:ital,wght@0,300..900;1,300..900&family=Source+Code+Pro:ital,wght@0,200..900;1,200..900&display=swap"
rel="stylesheet"
/>
<script>
document.addEventListener("DOMContentLoaded", () => {
const lskey = "dsnb-theme";
const theme = localStorage.getItem(lskey);
if (theme) {
document.body.parentElement.setAttribute("data-theme", theme);
} else {
document.body.parentElement.setAttribute("data-theme", "dark");
}
const themeSwitch = document.getElementById("theme-switch");
themeSwitch.checked =
document.body.parentElement.getAttribute("data-theme") === "dark";
populatePosts();
});
function toggleTheme() {
let theme = document.body.parentElement.getAttribute("data-theme");
if (theme === "dark") {
document.body.parentElement.setAttribute("data-theme", "light");
} else {
document.body.parentElement.setAttribute("data-theme", "dark");
}
localStorage.setItem(
"dsnb-theme",
document.body.parentElement.getAttribute("data-theme")
);
}
const pdfSvg = `<svg
xmlns="http://www.w3.org/2000/svg"
class="icon"
viewBox="0 0 512 512"
>
<path
fill="currentColor"
d="M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 144-208 0c-35.3 0-64 28.7-64 64l0 144-48 0c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128zM176 352l32 0c30.9 0 56 25.1 56 56s-25.1 56-56 56l-16 0 0 32c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-48 0-80c0-8.8 7.2-16 16-16zm32 80c13.3 0 24-10.7 24-24s-10.7-24-24-24l-16 0 0 48 16 0zm96-80l32 0c26.5 0 48 21.5 48 48l0 64c0 26.5-21.5 48-48 48l-32 0c-8.8 0-16-7.2-16-16l0-128c0-8.8 7.2-16 16-16zm32 128c8.8 0 16-7.2 16-16l0-64c0-8.8-7.2-16-16-16l-16 0 0 96 16 0zm80-112c0-8.8 7.2-16 16-16l48 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 32 32 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 48c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-64 0-64z"
/>
</svg>`;
async function populatePosts() {
const posts = await fetch("pages.json").then((res) => res.json());
posts.reverse();
const postsDiv = document.querySelector(".posts");
const fmt = new Intl.DateTimeFormat("en-US", {
dateStyle: "long",
});
for (const post of posts) {
const postDiv = document.createElement("div");
postDiv.classList.add("post");
const detailsDiv = document.createElement("div");
detailsDiv.classList.add("details");
const h2 = document.createElement("h2");
const a = document.createElement("a");
a.href = `page/${post.path}.html`;
if (post.pdf && post.html === false) {
a.href = `page/${post.path}.pdf`;
}
a.textContent = post.title;
h2.appendChild(a);
if (post.pdf && !("html" in post)) {
const pdfA = document.createElement("a");
pdfA.href = `page/${post.path}.pdf`;
pdfA.classList.add("pdf");
pdfA.innerHTML = pdfSvg;
h2.appendChild(pdfA);
}
const dateDiv = document.createElement("div");
dateDiv.classList.add("date");
dateDiv.textContent = fmt.format(new Date(post.date));
detailsDiv.appendChild(h2);
detailsDiv.appendChild(dateDiv);
const p = document.createElement("p");
p.textContent = post.description;
postDiv.appendChild(detailsDiv);
postDiv.appendChild(p);
postsDiv.appendChild(postDiv);
}
}
</script>
</head>
<body>
<main>
<header>
<div class="left">
<h1>Dipam's Notebook</h1>
<p>stuff about programming, math and more</p>
</div>
<div class="right">
<input
type="checkbox"
name="theme-switch"
id="theme-switch"
class="theme-switch"
onclick="toggleTheme()"
/>
<label for="theme-switch" class="theme-switch-label"></label>
</div>
</header>
<div class="posts"></div>
</main>
<footer>
<div class="contain">
<pre>@dipamsen</pre>
<a href="https://github.com/dipamsen">
<img
src="assets/github-mark.svg"
alt="github"
width="30"
class="light"
/>
<img
src="assets/github-mark-white.svg"
alt="github"
width="30"
class="dark"
/>
</a>
<p>
Powered by
<a href="https://typst.app" class="typst">Typst</a>
</p>
</div>
</footer>
</body>
</html>