barrettruth.com/src/components/Header.astro
2026-01-07 13:43:40 -06:00

63 lines
1.4 KiB
Text

---
const path = Astro.url.pathname;
const is404 = path === "/404.html" || path === "/404";
function deriveTopic() {
if (is404) return "/not-found";
if (path.startsWith("/about")) return "/about";
if (path === "/gist" || path.startsWith("/gist/")) return "/gist";
if (path === "/git" || path.startsWith("/git/")) return "/git";
return "";
}
const topic = deriveTopic();
const promptText = topic ? `barrett@ruth:~$ ${topic}` : "barrett@ruth:~$";
---
<header>
<a
href="/"
id="home-link"
class="home-link"
style="text-decoration: none; color: inherit"
>
<div class="terminal-container">
<span class="terminal-prompt">{promptText}</span>
<span class="terminal-cursor"></span>
</div>
</a>
</header>
<style>
@media (max-width: 640px) {
header {
flex-direction: row;
justify-content: space-between;
gap: 10px;
}
.terminal-container {
flex: 1 1 auto;
min-width: 0;
}
.terminal-prompt {
font-size: 0.9em;
}
#theme-toggle {
flex: 0 0 auto;
font-size: 1.2em;
}
}
</style>
<script is:inline>
const homeLink = document.getElementById("home-link");
homeLink.addEventListener("click", (e) => {
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
window.open("/", "_blank", "noopener");
}
});
</script>
<script src="/scripts/index.js" is:inline></script>