in src/template.ts [22:62]
function initCodeViewer() {
document.querySelectorAll("#sidebar a").forEach((link) => {
link.addEventListener("click", () =>
document.querySelector("body")?.classList.remove("nav-open")
);
});
for (const codeViewer of document.querySelectorAll(".code-viewer")) {
const codeBlocks = codeViewer.querySelectorAll<HTMLElement>(
"div.highlighter-rouge"
);
querySelectorOrThrow(
codeViewer,
HTMLElement,
"div.highlighter-rouge:first-child"
).style.display = "block";
codeViewer
.querySelectorAll<HTMLElement>("div.highlighter-rouge:not(:first-child)")
.forEach((e) => (e.style.display = "none"));
const ul = document.createElement("ul");
ul.classList.add("languages");
codeBlocks.forEach((block) => {
const li = document.createElement("li");
const a = document.createElement("a");
a.textContent = block.title;
a.addEventListener("click", () => {
ul.querySelectorAll("a").forEach((e) => e.classList.remove("active"));
a.classList.add("active");
codeBlocks.forEach((e) => (e.style.display = "none"));
block.style.display = "block";
});
li.appendChild(a);
ul.appendChild(li);
});
ul.firstElementChild?.firstElementChild?.classList.add("active");
codeViewer.prepend(ul);
}
}