-
+
- + algorithms + +
- + software + +
- + meditations + +
diff --git a/public/posts/designing-this-website/website-design.webp b/public/designing-this-website/website-design.webp similarity index 100% rename from public/posts/designing-this-website/website-design.webp rename to public/designing-this-website/website-design.webp diff --git a/public/posts/multithreading-a-gui/multi-threaded-implementation.webp b/public/multithreading-a-gui/multi-threaded-implementation.webp similarity index 100% rename from public/posts/multithreading-a-gui/multi-threaded-implementation.webp rename to public/multithreading-a-gui/multi-threaded-implementation.webp diff --git a/public/posts/multithreading-a-gui/single-threaded-design.webp b/public/multithreading-a-gui/single-threaded-design.webp similarity index 100% rename from public/posts/multithreading-a-gui/single-threaded-design.webp rename to public/multithreading-a-gui/single-threaded-design.webp diff --git a/public/posts/my-cp-setup/cp-setup.webp b/public/my-cp-setup/cp-setup.webp similarity index 100% rename from public/posts/my-cp-setup/cp-setup.webp rename to public/my-cp-setup/cp-setup.webp diff --git a/public/posts/proofs/graph.webp b/public/proofs/graph.webp similarity index 100% rename from public/posts/proofs/graph.webp rename to public/proofs/graph.webp diff --git a/public/posts/refactoring-a-state-machine/state-encoding.webp b/public/refactoring-a-state-machine/state-encoding.webp similarity index 100% rename from public/posts/refactoring-a-state-machine/state-encoding.webp rename to public/refactoring-a-state-machine/state-encoding.webp diff --git a/public/scripts/index.js b/public/scripts/index.js index e6076d6..4d04543 100644 --- a/public/scripts/index.js +++ b/public/scripts/index.js @@ -4,12 +4,25 @@ const TERMINAL_PROMPT = "barrett@ruth:~$ "; let typing = false; - let clearing = false; function promptEl() { return document.querySelector(".terminal-prompt"); } - + function promptTail() { + const el = promptEl(); + if (!el) return ""; + const s = el.textContent || ""; + return s.startsWith(TERMINAL_PROMPT) ? s.slice(TERMINAL_PROMPT.length) : s; + } + function setPromptTailImmediate(tail) { + const el = promptEl(); + if (!el) return; + el.textContent = TERMINAL_PROMPT + tail; + } + function persistPrompt() { + const el = promptEl(); + if (el) sessionStorage.setItem("terminalPromptText", el.textContent); + } (function restorePrompt() { const saved = sessionStorage.getItem("terminalPromptText"); const el = promptEl(); @@ -17,52 +30,80 @@ sessionStorage.removeItem("terminalPromptText"); })(); - function clearPrompt(delay, callback) { - if (clearing) return; - clearing = true; - const el = promptEl(); - if (!el) { - clearing = false; + function normalizeDisplayPath(pathname) { + let p = pathname.replace(/\/index\.html$/, "/").replace(/\.html$/, ""); + p = p.replace(/\/{2,}/g, "/"); + if (p !== "/" && p.endsWith("/")) p = p.slice(0, -1); + return p === "/" ? "" : p; + } + function displayPathFromHref(href) { + const url = new URL(href, location.origin); + return normalizeDisplayPath(url.pathname); + } + function currentDisplayPath() { + return normalizeDisplayPath(location.pathname); + } + function setDocTitleForPath(displayPath) { + if (!displayPath) { + document.title = "Barrett Ruth"; return; } - const excess = el.textContent.length - TERMINAL_PROMPT.length; - let i = 0; - function tick() { - if (i++ < excess) { - el.textContent = el.textContent.slice(0, -1); - setTimeout(tick, delay / Math.max(excess, 1)); - } else { - clearing = false; - callback && callback(); - } - } - tick(); + document.title = displayPath.slice(1); } - function typeTerminalPath(topic, delay, callback) { + function animateToDisplayPath(displayPath, totalMs, done) { if (typing) return; typing = true; - const el = promptEl(); - if (!el) return; - const txt = ` /${topic}`; - clearPrompt(delay, () => { - let i = 0; - function step() { - if (i < txt.length) { - el.textContent += txt.charAt(i++); - setTimeout(step, delay / txt.length); - } else { - typing = false; - callback && callback(); - } - } - step(); - }); - } - function persistPrompt() { const el = promptEl(); - if (el) sessionStorage.setItem("terminalPromptText", el.textContent); + if (!el) { + typing = false; + return; + } + + const targetTail = displayPath ? " " + displayPath : ""; + const curTail = promptTail(); + + let i = 0; + const max = Math.min(curTail.length, targetTail.length); + while (i < max && curTail.charAt(i) === targetTail.charAt(i)) i++; + + const delSteps = curTail.length - i; + const typeSteps = targetTail.length - i; + const totalSteps = delSteps + typeSteps; + + if (totalSteps === 0) { + typing = false; + done && done(); + return; + } + + const stepMs = totalMs / totalSteps; + + let delCount = 0; + function tickDelete() { + if (delCount < delSteps) { + setPromptTailImmediate(curTail.slice(0, curTail.length - delCount - 1)); + delCount++; + setTimeout(tickDelete, stepMs); + } else { + let j = 0; + function tickType() { + if (j < typeSteps) { + setPromptTailImmediate( + curTail.slice(0, i) + targetTail.slice(i, i + j + 1), + ); + j++; + setTimeout(tickType, stepMs); + } else { + typing = false; + done && done(); + } + } + tickType(); + } + } + tickDelete(); } function renderPosts(topic) { @@ -76,11 +117,13 @@ const div = document.createElement("div"); div.className = "post"; const a = document.createElement("a"); - const slug = post.id - .split("/") - .pop() - .replace(/\.mdx?$/, ""); - a.href = `/posts/${topic}/${slug}.html`; + const slug = + post.slug || + post.id + ?.split("/") + .pop() + ?.replace(/\.mdx?$/, ""); + a.href = `/${topic}/${slug}.html`; a.textContent = post.data.title; a.style.textDecoration = "underline"; div.appendChild(a); @@ -94,14 +137,14 @@ e.preventDefault(); if (typing) return; - const topic = link.dataset.topic.toLowerCase(); + const path = window.location.pathname; + const isHome = path === "/" || path === "/index.html"; + const topic = link.dataset.topic?.toLowerCase() || ""; const href = link.getAttribute("href") || "/"; const delay = 500; - const path = window.location.pathname; const colorFn = window.getTopicColor || (() => ""); - const topics = document.querySelectorAll("[data-topic]"); - topics.forEach((t) => { + document.querySelectorAll("[data-topic]").forEach((t) => { t.classList.remove("active"); t.style.color = ""; }); @@ -109,27 +152,29 @@ const c = colorFn(topic); if (c) link.style.color = c; - typeTerminalPath(topic, delay, () => { - persistPrompt(); + const displayPath = isHome ? `/${topic}` : displayPathFromHref(href); - if (path === "/" || path === "/index.html") { - if (window.postsByCategory && window.postsByCategory[topic]) { - renderPosts(topic); - return; - } + animateToDisplayPath(displayPath, delay, () => { + if ( + isHome && + topic && + window.postsByCategory && + window.postsByCategory[topic] + ) { + renderPosts(topic); + return; } + persistPrompt(); const isMail = href.startsWith("mailto:"); if (isMail) { window.location.href = href; return; } - if (link.target === "_blank") { window.open(href, "_blank"); return; } - window.location.href = href; }); } @@ -141,25 +186,31 @@ const isHome = window.location.pathname === "/" || window.location.pathname === "/index.html"; + const delay = 500; if (isHome) { - clearPrompt(500, () => { + animateToDisplayPath("", delay, () => { const posts = document.getElementById("posts"); if (posts) posts.innerHTML = ""; - const topics = document.querySelectorAll("[data-topic].active"); - topics.forEach((t) => { + document.querySelectorAll("[data-topic].active").forEach((t) => { t.classList.remove("active"); t.style.color = ""; }); + setDocTitleForPath(""); }); } else { persistPrompt(); - clearPrompt(500, () => { + animateToDisplayPath("", delay, () => { window.location.href = "/"; }); } } document.addEventListener("DOMContentLoaded", () => { + const initial = currentDisplayPath(); + if (initial) setPromptTailImmediate(" " + initial); + else setPromptTailImmediate(""); + if (initial) setDocTitleForPath(initial); + document.body.addEventListener("click", (e) => { if (e.target.closest(".home-link")) return handleHomeClick(e); if (e.target.closest("[data-topic]")) return handleDataTopicClick(e); @@ -172,7 +223,7 @@ if (!link) return; const color = (window.getTopicColor && - window.getTopicColor(link.dataset.topic.toLowerCase())) || + window.getTopicColor(link.dataset.topic?.toLowerCase() || "")) || ""; if (color) link.style.color = color; }, diff --git a/src/components/Header.astro b/src/components/Header.astro index 781d626..14e60ad 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -7,10 +7,6 @@ function deriveTopic() { if (path.startsWith("/about")) return "/about"; if (path === "/gist" || path.startsWith("/gist/")) return "/gist"; if (path === "/git" || path.startsWith("/git/")) return "/git"; - if (path.startsWith("/posts/")) { - const parts = path.replace(/\/+$/, "").split("/"); - if (parts.length >= 3) return "/" + parts[2]; - } return ""; } @@ -27,7 +23,9 @@ const promptText = topic ? `barrett@ruth:~$ ${topic}` : "barrett@ruth:~$";
@@ -57,4 +55,3 @@ const promptText = topic ? `barrett@ruth:~$ ${topic}` : "barrett@ruth:~$"; - diff --git a/src/content/posts/algorithms/extrema-circular-buffer.mdx b/src/content/algorithms/extrema-circular-buffer.mdx similarity index 100% rename from src/content/posts/algorithms/extrema-circular-buffer.mdx rename to src/content/algorithms/extrema-circular-buffer.mdx diff --git a/src/content/posts/algorithms/leetcode-daily.mdx b/src/content/algorithms/leetcode-daily.mdx similarity index 100% rename from src/content/posts/algorithms/leetcode-daily.mdx rename to src/content/algorithms/leetcode-daily.mdx diff --git a/src/content/posts/algorithms/models-of-production.mdx b/src/content/algorithms/models-of-production.mdx similarity index 100% rename from src/content/posts/algorithms/models-of-production.mdx rename to src/content/algorithms/models-of-production.mdx diff --git a/src/content/posts/algorithms/proofs.mdx b/src/content/algorithms/proofs.mdx similarity index 99% rename from src/content/posts/algorithms/proofs.mdx rename to src/content/algorithms/proofs.mdx index 557050e..f867cea 100644 --- a/src/content/posts/algorithms/proofs.mdx +++ b/src/content/algorithms/proofs.mdx @@ -196,7 +196,7 @@ Count-Pairs($l_1$, $l_2$, $r_1$, $r_2$, $k$): Each value of $n$ corresponds to a line with slope $k^n$ because $y/x=k^n\leftrightarrow y=x\cdot k^n$. The problem can be visualized as follows: - + It is sufficient to count the number of ordered $(x,y)$ pairs for all valid $n$. Because $y=x\cdot k^n\leftrightarrow n=log_k(y/x)$, $n\in [log_k(l_2/r_1), log_k(r_2/l_1)]$. diff --git a/src/content/posts/autonomous-racing/multithreading-a-gui.mdx b/src/content/autonomous-racing/multithreading-a-gui.mdx similarity index 97% rename from src/content/posts/autonomous-racing/multithreading-a-gui.mdx rename to src/content/autonomous-racing/multithreading-a-gui.mdx index 48eacef..0e5958b 100644 --- a/src/content/posts/autonomous-racing/multithreading-a-gui.mdx +++ b/src/content/autonomous-racing/multithreading-a-gui.mdx @@ -47,7 +47,7 @@ The Qt Framework is quite complex and beyond the scope of this post. Big picture How do we optimize this? It is necessary to take a step back and observe the structure of the entire application: - + Many flaws are now clear: @@ -68,7 +68,7 @@ First, let's pin down what exactly can be parallelized. This lead me to the follow structure: - + - Three callback groups are triggered at differing intervals according to their urgency on the GUI node - A thread-safe queue[^2] processes all ingested data for each callback group diff --git a/src/content/posts/autonomous-racing/refactoring-a-state-machine.mdx b/src/content/autonomous-racing/refactoring-a-state-machine.mdx similarity index 99% rename from src/content/posts/autonomous-racing/refactoring-a-state-machine.mdx rename to src/content/autonomous-racing/refactoring-a-state-machine.mdx index 44d74d2..cfccf35 100644 --- a/src/content/posts/autonomous-racing/refactoring-a-state-machine.mdx +++ b/src/content/autonomous-racing/refactoring-a-state-machine.mdx @@ -101,7 +101,7 @@ Considering each element of the state machine, I simplified it into the followin Since we only have $N\ll 32$ vehicle flags and $M\ll 32$ track flags, all of this information (all of the state flags) can be encoded in a `uint32_t`: - + The state must also store a few other relevant details: diff --git a/src/content/config.ts b/src/content/config.ts index dfa9942..7f99dbe 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,36 +1,17 @@ import { defineCollection, z } from "astro:content"; -const postsCollection = defineCollection({ - type: "content", - schema: z.object({ - title: z.string(), - description: z.string().optional(), - date: z.string().optional(), - useKatex: z.boolean().optional().default(false), - useD3: z.boolean().optional().default(false), - scripts: z.array(z.string()).optional(), - }), -}); - -const gistsCollection = defineCollection({ - type: "content", - schema: z.object({ - title: z.string(), - description: z.string().optional(), - date: z.string().optional(), - }), -}); - -const gitsCollection = defineCollection({ - type: "content", - schema: z.object({ - title: z.string(), - date: z.string().optional(), - }), +const base = z.object({ + title: z.string(), + description: z.string().optional(), + date: z.string().optional(), }); export const collections = { - posts: postsCollection, - gists: gistsCollection, - git: gitsCollection, + algorithms: defineCollection({ type: "content", schema: base }), + software: defineCollection({ type: "content", schema: base }), + meditations: defineCollection({ type: "content", schema: base }), + "autonomous-racing": defineCollection({ type: "content", schema: base }), + + git: defineCollection({ type: "content", schema: base }), + gists: defineCollection({ type: "content", schema: base }), }; diff --git a/src/content/git/git-server.mdx b/src/content/git/git-server.mdx index 9eba2a2..a68374a 100644 --- a/src/content/git/git-server.mdx +++ b/src/content/git/git-server.mdx @@ -1,6 +1,6 @@ --- -title: "git-server.git" +title: "git-server" date: "08/10/2025" --- -the code for my git python server, hosted on [lightsail](https://aws.amazon.com/lightsail/) +the code for my git python server hosted with [lightsail](https://aws.amazon.com/lightsail/) diff --git a/src/content/git/wp.mdx b/src/content/git/wp.mdx index e2818f1..8739bab 100644 --- a/src/content/git/wp.mdx +++ b/src/content/git/wp.mdx @@ -1,5 +1,5 @@ --- -title: "wp.git" +title: "wp" date: "07/10/2025" --- diff --git a/src/content/posts/meditations/suck-less-or-suck-more.mdx b/src/content/meditations/suck-less-or-suck-more.mdx similarity index 100% rename from src/content/posts/meditations/suck-less-or-suck-more.mdx rename to src/content/meditations/suck-less-or-suck-more.mdx diff --git a/src/content/posts/meditations/the-problem-with-cs-curricula.mdx b/src/content/meditations/the-problem-with-cs-curricula.mdx similarity index 100% rename from src/content/posts/meditations/the-problem-with-cs-curricula.mdx rename to src/content/meditations/the-problem-with-cs-curricula.mdx diff --git a/src/content/posts/software/cp.nvim.mdx b/src/content/software/cp.nvim.mdx similarity index 100% rename from src/content/posts/software/cp.nvim.mdx rename to src/content/software/cp.nvim.mdx diff --git a/src/content/posts/software/designing-this-website.mdx b/src/content/software/designing-this-website.mdx similarity index 96% rename from src/content/posts/software/designing-this-website.mdx rename to src/content/software/designing-this-website.mdx index 4956398..e3b8698 100644 --- a/src/content/posts/software/designing-this-website.mdx +++ b/src/content/software/designing-this-website.mdx @@ -44,7 +44,7 @@ But I did not actually _need_ any of them to make this site look decent. ## what i've learned -Of course, most people build simple websites like these to learn a new technology or framework, not to use an optimal tool. That's actually why I [hosted this website on AWS](/posts/software/from-github-pages-to-aws.html). +Of course, most people build simple websites like these to learn a new technology or framework, not to use an optimal tool. That's actually why I [hosted this website on AWS](/software/from-github-pages-to-aws.html). Building this website with truly bare-bones technologies has made me appreciate _why_ these web frameworks have emerged. @@ -74,7 +74,7 @@ A user request can be modelled as follows: 4. CloudFront checks its edge caches for the requested content. If the content is stale or not cached, CloudFront fetches the content from S3. Otherwise, it uses the cached content from an edge server. 5. CloudFront returns the content to the user's browser. - + ## difficulties diff --git a/src/content/posts/software/hosting-a-git-server.mdx b/src/content/software/hosting-a-git-server.mdx similarity index 100% rename from src/content/posts/software/hosting-a-git-server.mdx rename to src/content/software/hosting-a-git-server.mdx diff --git a/src/content/posts/software/my-cp-setup.mdx b/src/content/software/my-cp-setup.mdx similarity index 94% rename from src/content/posts/software/my-cp-setup.mdx rename to src/content/software/my-cp-setup.mdx index c428b2c..58bbd91 100644 --- a/src/content/posts/software/my-cp-setup.mdx +++ b/src/content/software/my-cp-setup.mdx @@ -26,7 +26,7 @@ That's it. The `makefile` relies on some scripts that compile code and run the c # neovim integration - + Leveraging [LuaSnip](https://github.com/L3MON4D3/LuaSnip), a custom `CP` user command, and some scripting for window management and asynchronous jobs, I'm able to: diff --git a/src/layouts/GitLayout.astro b/src/layouts/GitLayout.astro index 489e1a1..46c0ba1 100644 --- a/src/layouts/GitLayout.astro +++ b/src/layouts/GitLayout.astro @@ -1,64 +1,31 @@ --- -import BaseLayout from "./BaseLayout.astro"; -import { getTopicColor } from "../utils/colors.js"; - -interface Props { - frontmatter: { - title: string; - description?: string; - date?: string; - useKatex?: boolean; - useD3?: boolean; - scripts?: string[]; - }; -} - const { frontmatter, post } = Astro.props; -const { title, description, useKatex = false, useD3 = false } = frontmatter; - -const filePath = post?.id || ""; -const category = filePath.split("/")[0]; - -const topicColor = getTopicColor(category); --- -{frontmatter.description}
+ ) + }> {cloneCommand}
- > {cloneCommand}
+