Skip to content

Commit 1eaf14b

Browse files
committed
Tracks: subsets of the course that you can follow
1 parent fa778aa commit 1eaf14b

File tree

5 files changed

+91
-11
lines changed

5 files changed

+91
-11
lines changed

src/_includes/layout.jlhtml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ $(pluto_head)
8282
</form>
8383
</div>
8484
</li>
85+
<li>
86+
<div class="track-chooser">
87+
<label>
88+
<h2>Choose your track:</h2>
89+
<select>
90+
<option value="">Choose...</option>
91+
<option value="julia">💻 Julia programming</option>
92+
<option value="math">🎨 Mathematics</option>
93+
<option value="climate">🌎 Climate science</option>
94+
<option value="data">📊 Data science</option>
95+
</select>
96+
</label>
97+
</div>
98+
</li>
8599
$(let
86100
sidebar_data = Base.include(@__MODULE__, joinpath(@__DIR__, "..", "sidebar data.jl"))
87101
sections = sidebar_data["main"]
@@ -100,22 +114,23 @@ $(pluto_head)
100114

101115
name = get(output.frontmatter, "title", basename(input.relative_path))
102116
desc = get(output.frontmatter, "description", nothing)
117+
tags = get(output.frontmatter, "tags", String[])
103118
active = page.url == other_page.url
104119

105120
homework_number = get(output.frontmatter, "homework_number", nothing)
106121

107122
href = root_url * "/" * other_page.url
123+
124+
class = [
125+
active ? "active" : nothing,
126+
homework_number === nothing ? "lecture" : "homework",
127+
("tag_$(replace(x, " "=>"_"))" for x in tags)...,
128+
]
108129

109130
if homework_number === nothing
110-
@htl("""<li class=$([
111-
active ? "active" : nothing,
112-
"lecture",
113-
])><a href=$(href) title=$(desc)><span class="entry-number">$(number)</span> $(name)</a></li>""")
131+
@htl("""<li class=$(class)><a href=$(href) title=$(desc)><span class="entry-number">$(number)</span> $(name)</a></li>""")
114132
else
115-
@htl("""<li class=$([
116-
active ? "active" : nothing,
117-
"homework",
118-
])><a href=$(href) title=$(desc)><span class="entry-number">Homework $(homework_number):</span> $(name)</a></li>""")
133+
@htl("""<li class=$(class)><a href=$(href) title=$(desc)><span class="entry-number">Homework $(homework_number):</span> $(name)</a></li>""")
119134
end
120135
end for other_page in pages
121136
])

src/_includes/welcome.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ layout: "layout.jlhtml"
8787
8888
name = get(output.frontmatter, "title", basename(input.relative_path))
8989
desc = get(output.frontmatter, "description", nothing)
90-
active = page.url == other_page.url
90+
tags = get(output.frontmatter, "tags", String[])
9191
9292
image = get(output.frontmatter, "image", nothing)
9393
94-
image === nothing || isempty(image) ? nothing : @htl("""<a title=$(desc) class="no-decoration" href=$(root_url * "/" * other_page.url)>
94+
class = [
95+
"no-decoration",
96+
("tag_$(replace(x, " "=>"_"))" for x in tags)...,
97+
]
98+
99+
image === nothing || isempty(image) ? nothing : @htl("""<a title=$(desc) class=$(class) href=$(root_url * "/" * other_page.url)>
95100
<h3>$(name)</h3>
96101
<img src=$(image)>
97102
</a>""")

src/assets/scripts/sidebar.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,23 @@ window.addEventListener("click", function (e) {
1616

1717
console.info("zzzz")
1818
console.info(layout)
19+
20+
document.querySelectorAll(".track-chooser select").forEach((trackSelect) => {
21+
console.log(trackSelect)
22+
const ontrack = () => {
23+
let track = trackSelect.value
24+
25+
localStorage.setItem("chosen track", track)
26+
27+
let lectures_homeworks = Array.from(sidebar.querySelectorAll(".lecture,.homework"))
28+
29+
lectures_homeworks.forEach((el) => {
30+
let intrack = track === "" || el.classList.contains(`tag_track_${track}`) || el.classList.contains(`tag_welcome`)
31+
el.classList.toggle("not_in_track", !intrack)
32+
})
33+
}
34+
35+
trackSelect.value = localStorage.getItem("chosen track")
36+
ontrack()
37+
trackSelect.addEventListener("change", ontrack)
38+
})

src/assets/styles/index.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
--sidebar-accent-1: #c89393;
2626
--search-bg: hsl(78deg 10% 85%);
2727
--search-bg-accent: #f4f4f5;
28+
29+
--track-bg: hsl(56 50% 94% / 1);
30+
--track-bg-accent: #a3987c;
2831
}
2932

3033
@media (prefers-color-scheme: dark) {
@@ -33,9 +36,12 @@
3336
--faded-1: #b3b3b3;
3437
--faded-2: #999999;
3538

36-
--sidebar-accent-1: #8b736a;
39+
--sidebar-accent-1: #d0a493;
3740
--search-bg: #363b33;
3841
--search-bg-accent: #4d6542;
42+
43+
--track-bg: #545346;
44+
--track-bg-accent: #dad1b9;
3945
}
4046
}
4147

src/assets/styles/layout.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,40 @@
200200
#pages-sidebar li li:hover a {
201201
background-color: var(--sidebar-li-hover-bg);
202202
}
203+
#pages-sidebar li li.not_in_track {
204+
opacity: 0.4;
205+
}
206+
207+
/* TRACK CHOOSER */
208+
209+
.track-chooser {
210+
margin-top: 3em;
211+
padding: 0.5em;
212+
border: 3px solid var(--track-bg-accent);
213+
background: var(--track-bg);
214+
color: var(--fg);
215+
border-radius: 0.3em;
216+
display: flex;
217+
flex-direction: column;
218+
align-items: center;
219+
}
220+
221+
.track-chooser h2:not(#asdf) {
222+
font-weight: 900;
223+
font-family: sans-serif;
224+
font-style: normal;
225+
font-size: 1.2rem;
226+
margin-block-end: 0.3em;
227+
margin-block-start: 0;
228+
}
229+
230+
.track-chooser label {
231+
display: contents;
232+
}
233+
234+
.track-chooser select {
235+
max-width: 100%;
236+
}
203237

204238
/* SIDEBAR LOGO */
205239

0 commit comments

Comments
 (0)