feat: misc cleanups

This commit is contained in:
Barrett Ruth 2025-04-02 14:45:33 -04:00
parent 2c617c21c7
commit 255563f267
4 changed files with 21 additions and 10 deletions

View file

@ -39,7 +39,13 @@ const getTopicColor = (topicName) => {
return "#d50032";
case "algorithms":
return "#6a0dad";
default:
return "#000000";
}
};
const urlToTopic = () => window.location.pathname.split("/")[2];
const urlToTopic = () => {
const pathname = window.location.pathname.split("/");
if (pathname.length < 3) return "DNE";
return pathname[2];
};

View file

@ -1,8 +1,3 @@
document.documentElement.style.setProperty(
"--topic-color",
getTopicColor(urlToTopic()),
);
const tagToHeader = new Map([
["H2", "#"],
["H3", "##"],
@ -17,6 +12,11 @@ const setStyle = (h) => {
};
document.addEventListener("DOMContentLoaded", () => {
document.documentElement.style.setProperty(
"--topic-color",
getTopicColor(urlToTopic()),
);
document.querySelectorAll(".post-article h2").forEach(setStyle);
document.querySelectorAll(".post-article h3").forEach(setStyle);
});