feat: add posts structure

This commit is contained in:
Barrett Ruth 2024-06-08 19:39:42 -05:00
parent ccdb46c7a7
commit 3f660fcaf3
3 changed files with 102 additions and 41 deletions

View file

@ -83,7 +83,6 @@ footer {
.main { .main {
flex: 1; flex: 1;
display: flex; display: flex;
align-items: center;
} }
.header-links a, .header-links a,
@ -93,6 +92,8 @@ footer {
ul { ul {
list-style: none; list-style: none;
margin: 0;
padding: 0;
} }
a { a {
@ -100,27 +101,31 @@ a {
text-decoration: none; text-decoration: none;
} }
.content {
display: flex;
justify-content: space-between;
width: 100%;
}
.posts,
.topics {
padding: 0 40px;
align-self: center;
}
.topics { .topics {
font-size: 3em; font-size: 3em;
}
.posts {
font-size: 2em;
text-align: right;
flex: 1; flex: 1;
justify-content: space-between;
} }
.post { .post {
font-size: 2em; font-style: italic;
} margin-bottom: 25px;
.software a:hover {
color: #0073e6;
}
.economics a:hover {
color: #009975;
}
.trading a:hover {
color: #d50032;
}
.algorithms a:hover {
color: #6a0dad;
} }
.topic a { .topic a {
@ -138,17 +143,16 @@ a {
display: block; display: block;
margin-top: 4px; margin-top: 4px;
background: currentColor; background: currentColor;
width: 0;
right: 100%;
position: absolute;
transition: transition:
width 0.5s ease, width 0.5s ease,
right 0.5s ease; right 0.5s ease;
} }
.topic a:hover::after { .topic a:hover::after,
.topic a.active::after {
width: 100%; width: 100%;
right: 0; right: 0;
} }
.topic a:not(:hover)::after {
width: 0;
right: 100%;
}

View file

@ -22,21 +22,23 @@
</div> </div>
</header> </header>
<main class="main"> <main class="main">
<ul class="topics"> <div class="content">
<li class="topic software"> <ul class="topics">
<a href="/software" onclick="typechars(event)">Software</a> <li class="topic software">
</li> <a href="/software" onclick="typechars(event)">Software</a>
<li class="topic economics"> </li>
<a href="/economics" onclick="typechars(event)">Economics</a> <li class="topic economics">
</li> <a href="/economics" onclick="typechars(event)">Economics</a>
<li class="topic trading"> </li>
<a href="/trading" onclick="typechars(event)">Trading</a> <li class="topic trading">
</li> <a href="/trading" onclick="typechars(event)">Trading</a>
<li class="topic algorithms"> </li>
<a href="/algorithms" onclick="typechars(event)">Algorithms</a> <li class="topic algorithms">
</li> <a href="/algorithms" onclick="typechars(event)">Algorithms</a>
</ul> </li>
<div class="posts" id="posts"></div> </ul>
<div class="posts" id="posts"></div>
</div>
</main> </main>
<footer> <footer>
<div class="footer-links"> <div class="footer-links">

View file

@ -1,8 +1,18 @@
const postMapping = new Map([ const postMapping = new Map([
["Software", ["Post 1", "Post 2", "Post 3"]], [
["Economics", ["Economy 1", "Economy 2"]], "Software",
["Trading", ["Trade Secrets", "Market Trends"]], [
["Algorithms", ["Algorithm Challenges", "Data Structures 101"]], "from github pages to aws",
"designing this website",
"working in the terminal",
],
],
[
"Economics",
["romer-solow model", "the short run", "to invest or not to invest"],
],
["Trading", ["InteractiveBrokers TWS", "valuation"]],
["Algorithms", ["two pointers", "convex hull"]],
]); ]);
// TODO: ensure handling multiple clicks // TODO: ensure handling multiple clicks
@ -43,3 +53,48 @@ function typechars(e) {
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
document.querySelector(".prompt").innerHTML = "barrett@ruth:~$ "; document.querySelector(".prompt").innerHTML = "barrett@ruth:~$ ";
}); });
function applyColor(topic) {
switch (topic.parentElement.className.split(" ")[1]) {
case "software":
topic.style.color = "#0073e6";
break;
case "economics":
topic.style.color = "#009975";
break;
case "trading":
topic.style.color = "#d50032";
break;
case "algorithms":
topic.style.color = "#6a0dad";
break;
}
}
document.addEventListener("DOMContentLoaded", function () {
const topics = document.querySelectorAll(".topic a");
topics.forEach((topic) => {
topic.addEventListener("mouseenter", () => {
applyColor(topic);
});
topic.addEventListener("mouseleave", () => {
if (!topic.classList.contains("active")) {
topic.style.color = "";
}
});
topic.addEventListener("click", (e) => {
e.preventDefault();
topics.forEach((t) => {
t.classList.remove("active");
t.style.color = "";
});
topic.classList.add("active");
applyColor(topic);
});
});
});