This commit is contained in:
Barrett Ruth 2025-10-07 22:58:07 -04:00
parent 17d52f5b07
commit 5af8e1373e
9 changed files with 175 additions and 162 deletions

68
pnpm-lock.yaml generated
View file

@ -525,23 +525,23 @@ packages:
cpu: [x64]
os: [win32]
'@shikijs/core@3.4.2':
resolution: {integrity: sha512-AG8vnSi1W2pbgR2B911EfGqtLE9c4hQBYkv/x7Z+Kt0VxhgQKcW7UNDVYsu9YxwV6u+OJrvdJrMq6DNWoBjihQ==}
'@shikijs/core@3.13.0':
resolution: {integrity: sha512-3P8rGsg2Eh2qIHekwuQjzWhKI4jV97PhvYjYUzGqjvJfqdQPz+nMlfWahU24GZAyW1FxFI1sYjyhfh5CoLmIUA==}
'@shikijs/engine-javascript@3.4.2':
resolution: {integrity: sha512-1/adJbSMBOkpScCE/SB6XkjJU17ANln3Wky7lOmrnpl+zBdQ1qXUJg2GXTYVHRq+2j3hd1DesmElTXYDgtfSOQ==}
'@shikijs/engine-javascript@3.13.0':
resolution: {integrity: sha512-Ty7xv32XCp8u0eQt8rItpMs6rU9Ki6LJ1dQOW3V/56PKDcpvfHPnYFbsx5FFUP2Yim34m/UkazidamMNVR4vKg==}
'@shikijs/engine-oniguruma@3.4.2':
resolution: {integrity: sha512-zcZKMnNndgRa3ORja6Iemsr3DrLtkX3cAF7lTJkdMB6v9alhlBsX9uNiCpqofNrXOvpA3h6lHcLJxgCIhVOU5Q==}
'@shikijs/engine-oniguruma@3.13.0':
resolution: {integrity: sha512-O42rBGr4UDSlhT2ZFMxqM7QzIU+IcpoTMzb3W7AlziI1ZF7R8eS2M0yt5Ry35nnnTX/LTLXFPUjRFCIW+Operg==}
'@shikijs/langs@3.4.2':
resolution: {integrity: sha512-H6azIAM+OXD98yztIfs/KH5H4PU39t+SREhmM8LaNXyUrqj2mx+zVkr8MWYqjceSjDw9I1jawm1WdFqU806rMA==}
'@shikijs/langs@3.13.0':
resolution: {integrity: sha512-672c3WAETDYHwrRP0yLy3W1QYB89Hbpj+pO4KhxK6FzIrDI2FoEXNiNCut6BQmEApYLfuYfpgOZaqbY+E9b8wQ==}
'@shikijs/themes@3.4.2':
resolution: {integrity: sha512-qAEuAQh+brd8Jyej2UDDf+b4V2g1Rm8aBIdvt32XhDPrHvDkEnpb7Kzc9hSuHUxz0Iuflmq7elaDuQAP9bHIhg==}
'@shikijs/themes@3.13.0':
resolution: {integrity: sha512-Vxw1Nm1/Od8jyA7QuAenaV78BG2nSr3/gCGdBkLpfLscddCkzkL36Q5b67SrLLfvAJTOUzW39x4FHVCFriPVgg==}
'@shikijs/types@3.4.2':
resolution: {integrity: sha512-zHC1l7L+eQlDXLnxvM9R91Efh2V4+rN3oMVS2swCBssbj2U/FBwybD1eeLaq8yl/iwT+zih8iUbTBCgGZOYlVg==}
'@shikijs/types@3.13.0':
resolution: {integrity: sha512-oM9P+NCFri/mmQ8LoFGVfVyemm5Hi27330zuOBp0annwJdKH1kOLndw3zCtAVDehPLg9fKqoEx3Ht/wNZxolfw==}
'@shikijs/vscode-textmate@10.0.2':
resolution: {integrity: sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==}
@ -1695,8 +1695,8 @@ packages:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'}
shiki@3.4.2:
resolution: {integrity: sha512-wuxzZzQG8kvZndD7nustrNFIKYJ1jJoWIPaBpVe2+KHSvtzMi4SBjOxrigs8qeqce/l3U0cwiC+VAkLKSunHQQ==}
shiki@3.13.0:
resolution: {integrity: sha512-aZW4l8Og16CokuCLf8CF8kq+KK2yOygapU5m3+hoGw0Mdosc6fPitjM+ujYarppj5ZIKGyPDPP1vqmQhr+5/0g==}
simple-swizzle@0.2.2:
resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==}
@ -2075,7 +2075,7 @@ snapshots:
remark-parse: 11.0.0
remark-rehype: 11.1.2
remark-smartypants: 3.0.2
shiki: 3.4.2
shiki: 3.13.0
smol-toml: 1.3.4
unified: 11.0.5
unist-util-remove-position: 5.0.0
@ -2467,33 +2467,33 @@ snapshots:
'@rollup/rollup-win32-x64-msvc@4.41.0':
optional: true
'@shikijs/core@3.4.2':
'@shikijs/core@3.13.0':
dependencies:
'@shikijs/types': 3.4.2
'@shikijs/types': 3.13.0
'@shikijs/vscode-textmate': 10.0.2
'@types/hast': 3.0.4
hast-util-to-html: 9.0.5
'@shikijs/engine-javascript@3.4.2':
'@shikijs/engine-javascript@3.13.0':
dependencies:
'@shikijs/types': 3.4.2
'@shikijs/types': 3.13.0
'@shikijs/vscode-textmate': 10.0.2
oniguruma-to-es: 4.3.3
'@shikijs/engine-oniguruma@3.4.2':
'@shikijs/engine-oniguruma@3.13.0':
dependencies:
'@shikijs/types': 3.4.2
'@shikijs/types': 3.13.0
'@shikijs/vscode-textmate': 10.0.2
'@shikijs/langs@3.4.2':
'@shikijs/langs@3.13.0':
dependencies:
'@shikijs/types': 3.4.2
'@shikijs/types': 3.13.0
'@shikijs/themes@3.4.2':
'@shikijs/themes@3.13.0':
dependencies:
'@shikijs/types': 3.4.2
'@shikijs/types': 3.13.0
'@shikijs/types@3.4.2':
'@shikijs/types@3.13.0':
dependencies:
'@shikijs/vscode-textmate': 10.0.2
'@types/hast': 3.0.4
@ -2672,7 +2672,7 @@ snapshots:
prompts: 2.4.2
rehype: 13.0.2
semver: 7.7.2
shiki: 3.4.2
shiki: 3.13.0
tinyexec: 0.3.2
tinyglobby: 0.2.13
tsconfck: 3.1.6(typescript@5.8.3)
@ -4252,14 +4252,14 @@ snapshots:
shebang-regex@3.0.0: {}
shiki@3.4.2:
shiki@3.13.0:
dependencies:
'@shikijs/core': 3.4.2
'@shikijs/engine-javascript': 3.4.2
'@shikijs/engine-oniguruma': 3.4.2
'@shikijs/langs': 3.4.2
'@shikijs/themes': 3.4.2
'@shikijs/types': 3.4.2
'@shikijs/core': 3.13.0
'@shikijs/engine-javascript': 3.13.0
'@shikijs/engine-oniguruma': 3.13.0
'@shikijs/langs': 3.13.0
'@shikijs/themes': 3.13.0
'@shikijs/types': 3.13.0
'@shikijs/vscode-textmate': 10.0.2
'@types/hast': 3.0.4

View file

@ -1,18 +1,15 @@
---
const path = Astro.url.pathname;
const isHome = path === "/" || path === "/index.html";
const is404 = path === "/404.html" || path === "/404";
function getTopic() {
if (path.startsWith("/about")) {
return "/about";
}
const pathname = path.split("/");
if (pathname.length === 2 && pathname[1].endsWith(".html")) {
return "/" + pathname[1].replace(".html", "");
} else if (pathname.length >= 3) {
return "/" + pathname.slice(2, -1).join("/").replace(".html", "");
if (is404) return "/not-found";
if (path.startsWith("/about")) return "/about";
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 "";
}
@ -110,7 +107,8 @@ const promptText = topic ? `barrett@ruth:~$ ${topic}` : "barrett@ruth:~$";
topic.classList.remove("active");
topic.style.color = "";
});
document.getElementById("posts").innerHTML = "";
const posts = document.getElementById("posts");
if (posts) posts.innerHTML = "";
clearPrompt(500);
});
} else {
@ -155,3 +153,4 @@ const promptText = topic ? `barrett@ruth:~$ ${topic}` : "barrett@ruth:~$";
}
}
</style>

View file

@ -12,6 +12,17 @@ const postsCollection = defineCollection({
}),
});
const gistsCollection = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
description: z.string().optional(),
date: z.string().optional(),
}),
});
export const collections = {
posts: postsCollection,
gists: gistsCollection,
};

View file

@ -0,0 +1,24 @@
---
title: "countGoodNumbers.cpp"
date: "07/10/2025"
---
```cpp
class Solution {
public:
static constexpr long long MOD = 1e9 + 7;
long long mpow(long long a, long long b, long long mod=MOD) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
int countGoodNumbers(long long n) {
long long even = (n + 1) / 2, odd = n / 2;
return (mpow(5, even) * mpow(4, odd)) % MOD;
}
};
```

View file

@ -9,24 +9,29 @@ import BaseLayout from "../layouts/BaseLayout.astro";
</BaseLayout>
<script>
if (!location.pathname.endsWith("/404.html")) {
document.addEventListener("DOMContentLoaded", function () {
const terminalText = " /not-found";
const terminalPrompt = document.querySelector(".terminal-prompt");
const delay = 250;
if (!terminalPrompt) return;
document.addEventListener("DOMContentLoaded", function () {
const base = (window && window.TERMINAL_PROMPT) || "barrett@ruth:~$ ";
const el = document.querySelector(".terminal-prompt");
if (!el) return;
const type = () => {
const target = "/not-found";
let i = 0;
function typechar() {
if (i < terminalText.length) {
terminalPrompt.innerHTML += terminalText.charAt(i++);
setTimeout(typechar, delay / terminalText.length);
el.textContent = base;
(function step() {
if (i < target.length) {
el.textContent += target.charAt(i++);
setTimeout(step, 250 / target.length);
}
}
typechar();
});
}
})();
};
if (window && typeof window.clearPrompt === "function") {
window.clearPrompt(250, type);
} else {
type();
}
});
</script>
<style>
@ -45,3 +50,4 @@ import BaseLayout from "../layouts/BaseLayout.astro";
}
</style>
</BaseLayout>

View file

@ -1,99 +0,0 @@
---
import { getCollection } from "astro:content";
import BaseLayout from "../layouts/BaseLayout.astro";
export async function getStaticPaths() {
const categories = ["algorithms", "software", "meditations"];
return categories.map((category) => {
return {
params: { category },
props: { category },
};
});
}
const { category } = Astro.props;
const posts = await getCollection(
"posts",
(post) => post.data.category === category,
);
posts.sort((a, b) => {
const dateA = a.data.date ? new Date(a.data.date) : new Date(0);
const dateB = b.data.date ? new Date(b.data.date) : new Date(0);
return dateB.getTime() - dateA.getTime();
});
const capitalizedCategory =
category.charAt(0).toUpperCase() + category.slice(1);
---
<BaseLayout title={capitalizedCategory}>
<div class="content">
<h1>{capitalizedCategory}</h1>
<div class="posts">
{
posts.map((post) => (
<div class="post">
<a href={`/posts/${category}/${post.slug}`}>{post.data.title}</a>
{post.data.date && (
<time datetime={post.data.date}>
{new Date(post.data.date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
})}
</time>
)}
</div>
))
}
</div>
</div>
</BaseLayout>
<style>
.content {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
margin-bottom: 30px;
}
.posts {
padding: 0;
}
.post {
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
.post a {
display: block;
font-size: 1.2em;
text-decoration: underline;
color: var(--topic-color, inherit);
}
time {
display: block;
font-size: 0.9em;
color: #555;
margin-top: 5px;
}
</style>
<script define:vars={{ category }}>
document.addEventListener("DOMContentLoaded", function () {
document.documentElement.style.setProperty(
"--topic-color",
window.getTopicColor(category),
);
});
</script>

View file

@ -0,0 +1,23 @@
---
import { getCollection } from "astro:content";
import PostLayout from "../../layouts/PostLayout.astro";
export async function getStaticPaths() {
const gists = await getCollection("gists");
console.log(gists)
return gists.map((gist) => ({
params: { slug: gist.slug },
props: { gist },
}));
}
const { gist } = Astro.props;
const { Content } = await gist.render();
---
<PostLayout frontmatter={gist.data}>
<Content />
</PostLayout>

52
src/pages/git.astro Normal file
View file

@ -0,0 +1,52 @@
---
import BaseLayout from "../layouts/BaseLayout.astro";
const title = "Git Repositories";
---
<BaseLayout title={title}>
<slot name="head" slot="head">
<link rel="stylesheet" href="/styles/index.css" />
</slot>
<div class="content">
<ul class="topics" id="repo-list">
<li class="topic"></li>
</ul>
<div class="posts" id="posts"></div>
</div>
<script slot="scripts" type="module">
const listEl = document.getElementById("repo-list");
async function loadRepos() {
try {
const res = await fetch("https://git.barrettruth.com/api/repositories", { mode: "cors" });
if (!res.ok) throw new Error("HTTP " + res.status);
const data = await res.json();
const repos = Array.isArray(data?.repositories) ? data.repositories : [];
listEl.innerHTML = "";
repos.sort((a, b) => a.localeCompare(b));
for (const name of repos) {
const cls = `repo-${name}`;
const li = document.createElement("li");
li.className = `topic ${cls}`;
const a = document.createElement("a");
// a.href = `https://git.barrettruth.com/${name}`;
a.textContent = name;
a.setAttribute("data-topic", name);
li.appendChild(a);
listEl.appendChild(li);
}
} catch (_) {}
}
loadRepos();
</script>
</BaseLayout>

View file

@ -39,9 +39,6 @@ Object.keys(postsByCategory).forEach((category) => {
<li class="topic software">
<a href="#software" data-topic="software">software</a>
</li>
<li class="topic autonomous-racing">
<a href="#autonomous-racing" data-topic="autonomous-racing">autonomous racing</a>
</li>
<li class="topic meditations">
<a href="#meditations" data-topic="meditations">meditations</a>
</li>