feat: dynamically style each post

This commit is contained in:
Barrett Ruth 2024-06-22 13:53:26 -05:00
parent 8655cd7097
commit d3811df2ce
4 changed files with 27 additions and 18 deletions

View file

@ -1,8 +1,17 @@
const urlToTopic = () => {
return new URL(window.location.href).pathname.split("/")[2];
};
document.documentElement.style.setProperty(
"--topic-color",
getTopicColor(urlToTopic()),
);
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll("article h2").forEach((h2) => {
const mdHeading = document.createElement("span");
mdHeading.textContent = "# ";
mdHeading.style.color = "#0073e6";
mdHeading.style.color = getTopicColor(urlToTopic());
h2.prepend(mdHeading);
});
@ -20,7 +29,7 @@ document.addEventListener("DOMContentLoaded", () => {
const mdHeading = document.createElement("span");
mdHeading.textContent = "## ";
mdHeading.style.color = "#0073e6";
mdHeading.style.color = getTopicColor(urlToTopic());
h3.prepend(mdHeading);
h3.prepend(toggle);