Handouts script

This commit is contained in:
2025-11-03 10:17:41 -08:00
parent 1ab1eace1e
commit ba1337f97b

View File

@@ -72,7 +72,95 @@ Students never show up on time. Some come early, some come late. Warm-ups
are my solution to this problem: we hand these out as students walk in,
giving them something to do until we can start the lesson.
{{ handouts(group = "Warm-Ups") }}
<ul id="handout-ul-Warm-Ups" class="handout-ul"></ul>
<script>
fetch("https://git.betalupi.com/api/packages/Mark/generic/ormc-handouts/latest/index.json")
.then(res => res.json())
.then(out => {
out = out.sort((a, b) => (
a["title"].toLowerCase() < b["title"].toLowerCase()
));
out.forEach(element => {
if (element["group"] != "Warm-Ups") { return }
// Handout title
const title = document.createElement("span");
const title_a = document.createElement("strong");
title_a.appendChild(document.createTextNode(element["title"] + " "));
title.appendChild(title_a)
title.classList.add("handout-li-title");
// Handout title
const desc = document.createElement("span");
desc.appendChild(document.createTextNode(element["description"]));
desc.classList.add("handout-li-desc");
const handout_link = element["handout"];
const solutions_link = element["solutions"];
const links = document.createElement("span");
links.classList.add("handout-li-links");
const h = document.createElement("a");
h.appendChild(document.createTextNode("handout"))
h.href = handout_link;
if (solutions_link === null) {
links.appendChild(document.createTextNode("[ "));
links.appendChild(h);
links.appendChild(document.createTextNode(" ]"));
} else {
var s = document.createElement("a");
s.appendChild(document.createTextNode("solutions"))
s.href = solutions_link;
links.appendChild(document.createTextNode("[ "));
links.appendChild(h);
links.appendChild(document.createTextNode(" | "));
links.appendChild(s);
links.appendChild(document.createTextNode(" ]"));
}
// Add to main list
const item = document.createElement("li");
item.appendChild(title)
item.appendChild(links);
//item.appendChild(desc)
const list = document.getElementById("handout-ul-Warm-Ups");
list.insertBefore(item, list.children[0]);
})}
)
.catch(err => {
// Print fallback link if we failed to load json index
console.log(err)
const title = document.createElement("span");
const title_a = document.createElement("strong");
title_a.appendChild(document.createTextNode("Error: "));
title.appendChild(title_a)
title.appendChild(document.createTextNode("failed to load handouts, something broke."))
title.classList.add("handout-li-title");
const fallback = "https://git.betalupi.com/Mark/-/packages/generic/ormc-handouts/latest";
const link = document.createElement("a");
link.href = fallback
link.appendChild(document.createTextNode("ormc-handouts"));
const item_a = document.createElement("li");
item_a.appendChild(title)
const item_b = document.createElement("li");
item_b.appendChild(document.createTextNode("Fallback link: "))
item_b.appendChild(link)
const list = document.getElementById("handout-ul-Warm-Ups");
list.insertBefore(item_b, list.children[0]);
list.insertBefore(item_a, list.children[0]);
});
</script>
## Advanced
@@ -80,5 +168,93 @@ The highest level of the ORMC, and the group I spend most of my time with.
Students in ORMC Advanced are in high school, which means
they're ~14-18 years old.
{{ handouts(group = "Advanced") }}
<ul id="handout-ul-Advanced" class="handout-ul"></ul>
<script>
fetch("https://git.betalupi.com/api/packages/Mark/generic/ormc-handouts/latest/index.json")
.then(res => res.json())
.then(out => {
out = out.sort((a, b) => (
a["title"].toLowerCase() < b["title"].toLowerCase()
));
out.forEach(element => {
if (element["group"] != "Advanced") { return }
// Handout title
const title = document.createElement("span");
const title_a = document.createElement("strong");
title_a.appendChild(document.createTextNode(element["title"] + " "));
title.appendChild(title_a)
title.classList.add("handout-li-title");
// Handout title
const desc = document.createElement("span");
desc.appendChild(document.createTextNode(element["description"]));
desc.classList.add("handout-li-desc");
const handout_link = element["handout"];
const solutions_link = element["solutions"];
const links = document.createElement("span");
links.classList.add("handout-li-links");
const h = document.createElement("a");
h.appendChild(document.createTextNode("handout"))
h.href = handout_link;
if (solutions_link === null) {
links.appendChild(document.createTextNode("[ "));
links.appendChild(h);
links.appendChild(document.createTextNode(" ]"));
} else {
var s = document.createElement("a");
s.appendChild(document.createTextNode("solutions"))
s.href = solutions_link;
links.appendChild(document.createTextNode("[ "));
links.appendChild(h);
links.appendChild(document.createTextNode(" | "));
links.appendChild(s);
links.appendChild(document.createTextNode(" ]"));
}
// Add to main list
const item = document.createElement("li");
item.appendChild(title)
item.appendChild(links);
//item.appendChild(desc)
const list = document.getElementById("handout-ul-Advanced");
list.insertBefore(item, list.children[0]);
})}
)
.catch(err => {
// Print fallback link if we failed to load json index
console.log(err)
const title = document.createElement("span");
const title_a = document.createElement("strong");
title_a.appendChild(document.createTextNode("Error: "));
title.appendChild(title_a)
title.appendChild(document.createTextNode("failed to load handouts, something broke."))
title.classList.add("handout-li-title");
const fallback = "https://git.betalupi.com/Mark/-/packages/generic/ormc-handouts/latest";
const link = document.createElement("a");
link.href = fallback
link.appendChild(document.createTextNode("ormc-handouts"));
const item_a = document.createElement("li");
item_a.appendChild(title)
const item_b = document.createElement("li");
item_b.appendChild(document.createTextNode("Fallback link: "))
item_b.appendChild(link)
const list = document.getElementById("handout-ul-Advanced");
list.insertBefore(item_b, list.children[0]);
list.insertBefore(item_a, list.children[0]);
});
</script>
"#;