6 Commits
Author SHA1 Message Date
andwati ce65be8852 Move the TOC sidebar to the left of the article 2026-09-01 09:30:22 +03:00
andwati 0644dcf253 Add sticky sidebar TOC and widen the page for large screens
Writings detail pages now show the table of contents as a sticky
sidebar once there's room (>=74rem viewport), sharing its markup with
the existing inline TOC via a new TocList.astro so neither copy drifts.
Below that breakpoint it falls back to the original inline list.

Bumped .container--wide 64rem -> 76rem (home, bookshelf, and now
writings detail) so big monitors use more of the screen. The prose
column itself stays capped at 42rem for readability; the extra room is
what makes space for the TOC gutter. Verified at 390/900/1180/1920px.
2026-09-01 09:27:10 +03:00
andwati 27e53993d6 Swap shiki for highlight.js's core build for syntax highlighting
Shiki pulls in a WASM oniguruma engine and bundled theme/grammar JSON
for two full themes; highlight.js's core build plus only the 11
languages content actually uses is much thinner for the same job here.
Token colors now come straight from the design tokens (--accent,
--text-muted, ...) instead of shiki's dual-theme CSS vars, so they
already switch with the site's theme with no extra [data-theme] rules.
2026-09-01 09:20:12 +03:00
andwati 74a7f80b29 Render legacy callout shortcodes, add code syntax highlighting
Converts the note/tip/warning/danger `{% <tag> %}...{% </tag> %}` blocks
the posts→writings migration script left untranslated into styled
.callout markup (toml-content-loader.ts's renderCallouts(), styled in
global.css to match the new design system).

Also wires shiki into the same markdown pipeline for fenced code block
highlighting (github-light/github-dark, switched by the same
[data-theme]/prefers-color-scheme pattern tokens.css already uses).

Also records the Three.js centerpiece's perf budget check in TODO.md:
scene is trivially light (well under 10k triangles, 100+fps uncapped);
the ~130KB gzip payload is three.js core itself, not a tree-shaking gap
(verified named imports change nothing - sideEffects:false already lets
Rollup shake fully), and the script is a deferred module that doesn't
block first paint. No code changes needed there.
2026-09-01 09:14:29 +03:00
andwati c035aca132 Add OG image auto-generation for writings, portfolio, and bookshelf
Replaces the legacy Zola script, which was hard-coded to the retired
"CASE FILE" branding, with scripts/generate-og-images.astro-site.mjs
built on the new design system's dark palette + Fraunces/JetBrains Mono.
Base.astro now renders og:image/twitter:image from a per-page ogImage
prop, wired into the writings and bookshelf detail pages.

Uses static-weight Fraunces/Newsreader font packages rather than the
variable fonts the site ships elsewhere, since satori's opentype.js
parser throws on their fvar table.
2026-09-01 08:59:42 +03:00
andwati 9ee9795645 Normalize distributed systems tag to kebab-case 2026-09-01 08:54:15 +03:00
36 changed files with 831 additions and 80 deletions
+40 -13
View File
@@ -43,12 +43,14 @@ approved plan for full rationale on each decision referenced below.
Scholar nor arXiv offers a reliable image source for papers, so
`cover_image` stays manually-set for papers (or gets one later from
the OG-image pipeline below)
- [ ] OG image auto-generation extended from the legacy per-post script to
all three content types (writings, portfolio, bookshelf) — **blocked
on the design system**: `scripts/generate-og-images.mjs` is hard-coded
to the old "CASE FILE" hacker-terminal branding being fully replaced;
building this now would just be redone once the new visual identity
lands
- [x] OG image auto-generation extended to all three content types
(writings, portfolio, bookshelf) using the new design system —
`scripts/generate-og-images.astro-site.mjs`, wired into `apps/site`'s
build script; `Base.astro` renders `og:image`/`twitter:image` from a
per-page `ogImage` prop (writings/bookshelf detail pages wire it in;
portfolio has no detail page yet to wire it into). Uses static-weight
Fraunces/Newsreader font packages, not the variable fonts the site
ships — satori's opentype.js parser can't read the variable fvar table
- [x] `llms.txt` generation extended to cover all content types — unblocked
once `site.config.ts` existed (built above for feeds/meta anyway):
`scripts/generate-llms.astro-site.mjs` reads all four content
@@ -88,15 +90,27 @@ approved plan for full rationale on each decision referenced below.
- [x] Fallback for `prefers-reduced-motion` (skips rotation/entrance
animation) and no-WebGL (`supportsWebGL()` check hides the canvas
entirely, falls back to a `<noscript>`-style plain count)
- [ ] Perf budget check on a low-end/mobile profile — not yet measured
- [x] Perf budget check — scene is trivially light (24 nodes, 12x12-segment
spheres, a handful of line-segment edges: well under 10k triangles),
renders at 100+fps uncapped with no dropped frames. The real cost is
the JS payload: three.js core pulls in ~130KB gzip / ~106KB brotli
regardless of `import *` vs named imports (`sideEffects: false`
already lets Rollup tree-shake fully; tried named imports, no size
change). That script is a deferred module (doesn't block first
paint/DCL) and the page was interactive in ~270ms in testing. No
code changes made — budget is fine as shipped
## Content features carried over from the Zola site
- [x] Series-nav (multi-part post series) — `writings/[...slug].astro`,
uses the existing `extra.series`/`extra.series_index` fields
- [x] Table of contents — inline only, no separate sidebar layout yet (that's
a design-system concern); heading ids + `headings` metadata now flow
through `toml-content-loader.ts` so `render(entry)` exposes them
- [x] Table of contents — sticky sidebar on desktop (>=74rem), falls back to
the original inline list below the tags on narrower viewports; same
heading data rendered via a shared `TocList.astro` so the two aren't
duplicated markup by hand. `.container--wide` bumped 64rem → 76rem so
big monitors use more of the screen (prose column itself stays capped
at 42rem for readability — the extra width is the TOC gutter);
verified at 390/900/1180/1920px with no distortion at any width
- [x] Prev/next post navigation
- [x] Related posts (tag-based, tag-overlap ranked, limit 3)
- [x] Per-tag descriptions on tag archive pages — `/tags/` + `/tags/[tag]/`,
@@ -106,6 +120,14 @@ approved plan for full rationale on each decision referenced below.
`Base.astro`)
- [x] RSS/JSON feeds — `/rss.xml`, `/feed.json`
- [x] Sitemap + robots.txt — `@astrojs/sitemap`, static `public/robots.txt`
- [x] Code block syntax highlighting — `toml-content-loader.ts` renders
fenced code blocks through `highlight.js`'s core build with only the
11 languages content actually uses registered (no bundled-theme/WASM
grammar weight like shiki, which was tried first and swapped out for
this lighter option); `.hljs-*` token classes in `global.css` are
colored from the existing design tokens (`--accent`, `--text-muted`,
...), so they already switch with the site's theme with no extra
`[data-theme]` rules needed
## Search & comments
@@ -132,9 +154,14 @@ approved plan for full rationale on each decision referenced below.
additive only (`content/posts/` untouched), re-runnable/idempotent.
2 of 20 posts (`from-c-to-machine-code`,
`self-hosting-gitea-and-mirroring-github`) use note/tip/warning/danger
callout shortcodes with no Astro equivalent yet — flagged by the
script, needs a real component once the design system exists
(**not blocking**, just noted for later)
callout shortcodes — flagged by the script, still left as-is in the
body text
- [x] note/tip/warning/danger callout shortcode rendering — the legacy
`{% <note> %} ... {% </note> %}` blocks are converted to styled
`.callout` markup by `toml-content-loader.ts`'s `renderCallouts()`
(runs before the body's markdown parse), styled in `global.css` to
match the new design system. Verified in-browser on
`from-c-to-machine-code`
- [x] Preserve slugs/URLs via redirects — the script generates 301s from
`/posts/<slug>/` to `/writings/<slug>/` into `sws.toml`, idempotently
- [ ] Migrate `content/archive/`, `content/about.md` equivalents — holding
+3 -1
View File
@@ -8,7 +8,8 @@
"scripts": {
"dev": "astro dev",
"generate:llms": "node ../../scripts/generate-llms.astro-site.mjs",
"build": "pnpm run generate:llms && astro build && pagefind --site dist",
"generate:og": "node ../../scripts/generate-og-images.astro-site.mjs",
"build": "pnpm run generate:llms && pnpm run generate:og && astro build && pagefind --site dist",
"preview": "astro preview",
"check": "astro check",
"astro": "astro"
@@ -20,6 +21,7 @@
"@fontsource-variable/newsreader": "^5.3.0",
"@fontsource/jetbrains-mono": "^5.3.0",
"astro": "^7.2.9",
"highlight.js": "^11.12.0",
"marked": "^18.0.11",
"pagefind": "^1.5.2",
"smol-toml": "^1.8.0",
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+24
View File
@@ -0,0 +1,24 @@
---
interface Heading {
depth: number;
slug: string;
text: string;
}
interface Props {
headings: Heading[];
}
const { headings } = Astro.props;
---
<p class="meta">Table of Contents</p>
<ul>
{
headings.map((h) => (
<li style={{ marginLeft: `${(h.depth - 2) * 1}rem` }}>
<a href={`#${h.slug}`}>{h.text}</a>
</li>
))
}
</ul>
+15 -2
View File
@@ -11,22 +11,35 @@ interface Props {
description?: string;
/** Widens .container for dashboard-style layouts (currently just the homepage). */
wide?: boolean;
/** Site-root-relative path to a per-page OG image, e.g. /images/og/writings/foo.png */
ogImage?: string;
}
const { title, description, wide = false } = Astro.props;
const { title, description, wide = false, ogImage } = Astro.props;
const metaDescription = description ?? siteConfig.description;
const currentPath = Astro.url.pathname;
const copyrightRange = await copyrightYearRange();
const pageTitle = `${title} — ${siteConfig.title}`;
const ogImageUrl = new URL(ogImage ?? "/favicon.svg", siteConfig.baseUrl).href;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title} — {siteConfig.title}</title>
<title>{pageTitle}</title>
<meta name="description" content={metaDescription} />
<link rel="alternate" type="application/rss+xml" title={siteConfig.title} href="/rss.xml" />
<link rel="alternate" type="application/feed+json" title={siteConfig.title} href="/feed.json" />
<link rel="webmention" href="https://webmention.io/andwati.com/webmention" />
<meta property="og:type" content="website" />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={metaDescription} />
<meta property="og:url" content={Astro.url.href} />
<meta property="og:image" content={ogImageUrl} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={metaDescription} />
<meta name="twitter:image" content={ogImageUrl} />
<script is:inline>
// Runs before paint to avoid a flash of the wrong theme.
(function () {
+110 -1
View File
@@ -1,6 +1,18 @@
import { readdirSync, readFileSync, statSync } from "node:fs";
import { extname, join, relative } from "node:path";
import type { Loader } from "astro/loaders";
import hljs from "highlight.js/lib/core";
import hljsBash from "highlight.js/lib/languages/bash";
import hljsC from "highlight.js/lib/languages/c";
import hljsCss from "highlight.js/lib/languages/css";
import hljsDos from "highlight.js/lib/languages/dos";
import hljsIni from "highlight.js/lib/languages/ini";
import hljsJavascript from "highlight.js/lib/languages/javascript";
import hljsPowershell from "highlight.js/lib/languages/powershell";
import hljsPython from "highlight.js/lib/languages/python";
import hljsX86asm from "highlight.js/lib/languages/x86asm";
import hljsXml from "highlight.js/lib/languages/xml";
import hljsYaml from "highlight.js/lib/languages/yaml";
import { Marked } from "marked";
import { parse as parseToml } from "smol-toml";
@@ -33,6 +45,52 @@ function stripInlineMarkdown(text: string): string {
// as `headings`, matching the shape a built-in markdown loader would give.
let currentHeadings: Heading[] = [];
// highlight.js's core build (no bundled grammars) plus only the languages
// actually used in content/'s fenced code blocks — keeps the highlighter
// thin instead of shipping its full ~190-language bundle. Aliases below
// map every fence lang seen in content to one of these registered names.
hljs.registerLanguage("bash", hljsBash);
hljs.registerLanguage("c", hljsC);
hljs.registerLanguage("css", hljsCss);
hljs.registerLanguage("dos", hljsDos);
hljs.registerLanguage("ini", hljsIni);
hljs.registerLanguage("javascript", hljsJavascript);
hljs.registerLanguage("powershell", hljsPowershell);
hljs.registerLanguage("python", hljsPython);
hljs.registerLanguage("x86asm", hljsX86asm);
hljs.registerLanguage("xml", hljsXml);
hljs.registerLanguage("yaml", hljsYaml);
const LANG_ALIASES: Record<string, string> = {
asm: "x86asm",
bat: "dos",
gdb: "plaintext",
html: "xml",
js: "javascript",
ps1: "powershell",
sh: "bash",
svg: "xml",
toml: "ini",
txt: "plaintext",
zsh: "bash",
"": "plaintext",
};
function escapeHtml(text: string): string {
return text
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
function highlightCode(code: string, lang: string | undefined): string {
const resolved = LANG_ALIASES[lang ?? ""] ?? lang ?? "plaintext";
const inner = hljs.getLanguage(resolved)
? hljs.highlight(code, { language: resolved }).value
: escapeHtml(code);
return `<pre class="hljs"><code>${inner}</code></pre>`;
}
const marked = new Marked({
renderer: {
heading(token) {
@@ -42,9 +100,60 @@ const marked = new Marked({
currentHeadings.push({ depth: token.depth, slug, text: plainText });
return `<h${token.depth} id="${slug}">${html}</h${token.depth}>`;
},
code(token) {
return highlightCode(token.text, token.lang);
},
},
});
const CALLOUT_ICONS: Record<string, string> = {
note: '<circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line>',
tip: '<circle cx="12" cy="12" r="10"></circle><path d="M12 8v4"></path><path d="M12 16h.01"></path>',
warning:
'<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line>',
danger:
'<polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"></polygon><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line>',
};
const CALLOUT_TITLES: Record<string, string> = {
note: "Note",
tip: "Tip",
warning: "Warning",
danger: "Danger",
};
// Legacy Zola shortcode syntax carried over verbatim by the posts→writings
// migration script (which flagged, but didn't translate, these blocks —
// see scripts/migrate-posts-to-writings.mjs). Matches
// `{% <note> %}\n...body...\n{% </note> %}` for note/tip/warning/danger.
const CALLOUT_RE =
/\{%\s*<(note|tip|warning|danger)>\s*%\}\r?\n?([\s\S]*?)\r?\n?\{%\s*<\/\1>\s*%\}/g;
/** Replaces legacy callout shortcode blocks with the `.callout` markup
* (styled in global.css), rendering each block's inner markdown. Must run
* before the body's own `marked.parse()` call so the shortcode syntax
* doesn't get treated as literal paragraph text. */
async function renderCallouts(body: string): Promise<string> {
const matches = [...body.matchAll(CALLOUT_RE)];
if (!matches.length) return body;
let out = body;
for (const match of matches) {
const [full, tag, inner] = match;
const innerHtml = await marked.parseInline(inner.trim());
out = out.replace(
full,
`<aside class="callout callout-${tag}">
<div class="callout-header">
<svg class="callout-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${CALLOUT_ICONS[tag]}</svg>
<span class="callout-title">${CALLOUT_TITLES[tag]}</span>
</div>
<div class="callout-content">${innerHtml}</div>
</aside>`,
);
}
return out;
}
function walk(dir: string): string[] {
const out: string[] = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
@@ -95,7 +204,7 @@ export function tomlContentLoader(contentDir: string): Loader {
const relPath = relative(dirUrl.pathname, file);
const id = relPath.replace(/\/index\.md$/, "").replace(/\.md$/, "");
currentHeadings = [];
const trimmedBody = body.trim();
const trimmedBody = await renderCallouts(body.trim());
const html = await marked.parse(trimmedBody);
const wordCount = trimmedBody.split(/\s+/).filter(Boolean).length;
const readingMinutes = Math.max(1, Math.round(wordCount / 200));
@@ -21,7 +21,7 @@ const items = (await getCollection("bookshelf")).sort(
);
---
<Base title={entry.data.title} wide>
<Base title={entry.data.title} wide ogImage={`/images/og/bookshelf/${entry.id}.png`}>
<BookSpines
items={items.map((e) => ({ slug: e.id, title: e.data.title, coverImage: e.data.cover_image }))}
activeSlug={entry.id}
+103 -60
View File
@@ -1,5 +1,6 @@
---
import { getCollection, render } from "astro:content";
import TocList from "../../components/TocList.astro";
import Base from "../../layouts/Base.astro";
export async function getStaticPaths() {
@@ -51,68 +52,110 @@ const description =
const tocHeadings = headings.filter((h) => h.depth <= 3);
---
<Base title={entry.data.title} description={description}>
<h1>{entry.data.title}</h1>
<p class="meta">
{entry.data.date.toDateString()}
{entry.data.readingMinutes && <> · {entry.data.readingMinutes} min read</>}
{entry.data.updated && <> · updated {entry.data.updated.toDateString()}</>}
</p>
{tags.map((tag) => <a class="tag" href={`/tags/${tag}/`}>#{tag}</a>)}
<Base title={entry.data.title} description={description} wide ogImage={`/images/og/writings/${entry.id}.png`}>
<div class="article-layout">
<div class="article-main">
<h1>{entry.data.title}</h1>
<p class="meta">
{entry.data.date.toDateString()}
{entry.data.readingMinutes && <> · {entry.data.readingMinutes} min read</>}
{entry.data.updated && <> · updated {entry.data.updated.toDateString()}</>}
</p>
{tags.map((tag) => <a class="tag" href={`/tags/${tag}/`}>#{tag}</a>)}
{
series && (
<nav class="series-nav" aria-label={`Post series: ${series}`}>
<p class="meta">
Series: {series} ({(entry.data.extra?.series_index ?? 0)} / {seriesEntries.length})
</p>
<ol>
{seriesEntries.map((w) => (
<li aria-current={w.id === entry.id ? "page" : undefined}>
<a href={`/writings/${w.id}/`}>{w.data.title}</a>
</li>
))}
</ol>
{
series && (
<nav class="series-nav" aria-label={`Post series: ${series}`}>
<p class="meta">
Series: {series} ({(entry.data.extra?.series_index ?? 0)} / {seriesEntries.length})
</p>
<ol>
{seriesEntries.map((w) => (
<li aria-current={w.id === entry.id ? "page" : undefined}>
<a href={`/writings/${w.id}/`}>{w.data.title}</a>
</li>
))}
</ol>
</nav>
)
}
{
tocHeadings.length > 0 && (
<nav class="toc toc-inline" aria-label="Table of contents">
<TocList headings={tocHeadings} />
</nav>
)
}
<article>
<Content />
</article>
<nav class="post-nav" aria-label="Post navigation">
{prev && <a href={`/writings/${prev.id}/`}>← {prev.data.title}</a>}
{next && <a href={`/writings/${next.id}/`}>{next.data.title} →</a>}
</nav>
)
}
{
tocHeadings.length > 0 && (
<nav class="toc" aria-label="Table of contents">
<p class="meta">Table of Contents</p>
<ul>
{tocHeadings.map((h) => (
<li style={{ marginLeft: `${(h.depth - 2) * 1}rem` }}>
<a href={`#${h.slug}`}>{h.text}</a>
</li>
))}
</ul>
</nav>
)
}
{
related.length > 0 && (
<section>
<h2>Related Posts</h2>
{related.map((w) => (
<div class="card">
<h3>
<a href={`/writings/${w.id}/`}>{w.data.title}</a>
</h3>
</div>
))}
</section>
)
}
</div>
<article>
<Content />
</article>
<nav class="post-nav" aria-label="Post navigation">
{prev && <a href={`/writings/${prev.id}/`}>← {prev.data.title}</a>}
{next && <a href={`/writings/${next.id}/`}>{next.data.title} →</a>}
</nav>
{
related.length > 0 && (
<section>
<h2>Related Posts</h2>
{related.map((w) => (
<div class="card">
<h3>
<a href={`/writings/${w.id}/`}>{w.data.title}</a>
</h3>
</div>
))}
</section>
)
}
{
tocHeadings.length > 0 && (
<nav class="toc toc-sidebar" aria-label="Table of contents">
<TocList headings={tocHeadings} />
</nav>
)
}
</div>
</Base>
<style>
.article-layout {
display: grid;
grid-template-columns: minmax(0, 42rem);
justify-content: center;
align-items: start;
gap: var(--space-7);
}
.toc-sidebar {
display: none;
}
@media (min-width: 74rem) {
.article-layout {
grid-template-columns: 16rem minmax(0, 42rem);
}
.article-main {
order: 2;
}
.toc-inline {
display: none;
}
.toc-sidebar {
display: block;
order: 1;
position: sticky;
top: var(--space-6);
max-height: calc(100vh - var(--space-7));
overflow-y: auto;
}
}
</style>
+142 -1
View File
@@ -93,6 +93,58 @@ pre {
border: 1px solid var(--border);
}
/* highlight.js syntax highlighting (toml-content-loader.ts renders code
fences through hljs's core build). Colors are drawn from the existing
design tokens, so they already switch with the site's light/dark theme
without any extra [data-theme] rules here — see tokens.css. */
.hljs-comment,
.hljs-quote {
color: var(--text-muted);
font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-type,
.hljs-literal,
.hljs-link {
color: var(--accent);
}
.hljs-string,
.hljs-attr,
.hljs-symbol,
.hljs-addition {
color: #4a9c6d;
}
.hljs-number,
.hljs-meta,
.hljs-doctag {
color: #d1a53d;
}
.hljs-title,
.hljs-title.function_,
.hljs-title.class_,
.hljs-name {
color: var(--text);
font-weight: 600;
}
.hljs-deletion {
color: #d1502f;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: 700;
}
.container {
max-width: 42rem;
margin-inline: auto;
@@ -100,7 +152,41 @@ pre {
}
.container--wide {
max-width: 64rem;
max-width: 76rem;
}
.toc {
font-family: var(--font-mono);
font-size: var(--font-size-sm);
margin-bottom: var(--space-5);
}
.toc p.meta {
margin-bottom: var(--space-2);
}
.toc ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: var(--space-2);
}
.toc a {
text-decoration: none;
color: var(--text-muted);
}
.toc a:hover {
color: var(--accent);
}
.toc-sidebar {
padding-top: var(--space-1);
border-right: 1px solid var(--border);
padding-right: var(--space-4);
}
.eyebrow {
@@ -169,6 +255,61 @@ pre {
color: var(--accent);
}
.callout {
margin: 0 0 var(--space-5);
padding: var(--space-4) var(--space-5);
border: 1px solid var(--border);
border-left: 3px solid var(--callout-color, var(--accent));
border-radius: var(--radius-md);
background: var(--bg-elevated);
}
.callout-header {
display: flex;
align-items: center;
gap: var(--space-2);
margin-bottom: var(--space-2);
color: var(--callout-color, var(--accent));
}
.callout-icon {
width: 1.1em;
height: 1.1em;
flex-shrink: 0;
}
.callout-title {
font-family: var(--font-mono);
font-size: var(--font-size-sm);
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.callout-content {
color: var(--text);
}
.callout-content > :last-child {
margin-bottom: 0;
}
.callout-note {
--callout-color: var(--accent);
}
.callout-tip {
--callout-color: #4a9c6d;
}
.callout-warning {
--callout-color: #d1a53d;
}
.callout-danger {
--callout-color: #d1502f;
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
@@ -9,7 +9,7 @@ rating = 5
read_status = "reading"
[taxonomies]
tags = [ "distributed systems" ]
tags = [ "distributed-systems" ]
+++
+2
View File
@@ -16,6 +16,8 @@
},
"devDependencies": {
"@biomejs/biome": "^2.5.11",
"@fontsource/fraunces": "^5.3.0",
"@fontsource/newsreader": "^5.3.0",
"@resvg/resvg-js": "^2.6.2",
"concurrently": "^10.0.5",
"satori": "^0.29.0",
+25
View File
@@ -11,6 +11,12 @@ importers:
'@biomejs/biome':
specifier: ^2.5.11
version: 2.5.11
'@fontsource/fraunces':
specifier: ^5.3.0
version: 5.3.0
'@fontsource/newsreader':
specifier: ^5.3.0
version: 5.3.0
'@resvg/resvg-js':
specifier: ^2.6.2
version: 2.6.2
@@ -93,6 +99,9 @@ importers:
astro:
specifier: ^7.2.9
version: 7.2.9(@emnapi/[email protected])(@emnapi/[email protected])(@types/[email protected])([email protected])([email protected])
highlight.js:
specifier: ^11.12.0
version: 11.12.0
marked:
specifier: ^18.0.11
version: 18.0.11
@@ -1026,9 +1035,15 @@ packages:
'@fontsource-variable/[email protected]':
resolution: {integrity: sha512-rrzYi43qMpbzwuFtf9OkWH8sxAPVPcQQQEwXpPtwaKYeJ8yVg5aLs5kawmo1f2Q1t1M38TLmEKCkGVDsYwgdFw==}
'@fontsource/[email protected]':
resolution: {integrity: sha512-LEHTOBiZufQzAvnAe2rZ8ZknbDS28Q9kzwb0L+gZJEmjLGr8hhZ/5NuHXwDuHBWhVXYoiGGXmrb0H6Ko/RrHTg==}
'@fontsource/[email protected]':
resolution: {integrity: sha512-fqDfB5I9f1p1TV486aUgB9t8zP84P0O1FtQR5Ol9vjwPy+S+EIGlVYm1cvj2W5shcZMTg2nZFdVMoH5wFu8a1A==}
'@fontsource/[email protected]':
resolution: {integrity: sha512-AFR6ZKY89GNL+9qBI2P2+66NhD5bhOj/v6fsLnFYLM4E0JnMB1yKb+Ro8cA64i1hwAWoBfTq5CHJGWH1toLDkw==}
'@formatjs/[email protected]':
resolution: {integrity: sha512-+QoPW4csYALsQIl8GbN14igZzDbuwzcpWrku9nyMXlaqAlwRBgl5V+p0vWMGFqHOw37czNXaP/lEk4wbLgcmtA==}
@@ -4764,6 +4779,10 @@ packages:
[email protected]:
resolution: {integrity: sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==}
[email protected]:
resolution: {integrity: sha512-nbfWpyRMcMrPMmDwJB+dhX/eiaPKtc2RB+0QZskqJ3WjRA/FDS0e9hZrx8EC/lbEv8gXy98FcDbNa/dspAaJMg==}
engines: {node: '>=12.0.0'}
[email protected]:
resolution: {integrity: sha512-uu0VXUK52JhihhnN/MVVo1lvqNNuhoxkonqgO3IpjvQiGpJBdIXMGkofjQb/j9zvV7a1SW8U9g1FslWx/1HOiQ==}
@@ -8813,8 +8832,12 @@ snapshots:
'@fontsource-variable/[email protected]': {}
'@fontsource/[email protected]': {}
'@fontsource/[email protected]': {}
'@fontsource/[email protected]': {}
'@formatjs/[email protected]':
dependencies:
'@formatjs/intl-localematcher': 0.5.4
@@ -13571,6 +13594,8 @@ snapshots:
[email protected]: {}
[email protected]: {}
[email protected]: {}
[email protected]:
+365
View File
@@ -0,0 +1,365 @@
// Generates OG images for the new Astro site's writings, portfolio, and
// bookshelf entries, replacing the legacy Zola script (which was hard-coded
// to the retired "CASE FILE" branding). Output goes to
// apps/site/public/images/og/<type>/<slug>.png, wired into apps/site's
// build script (mirrors generate-llms.astro-site.mjs).
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Resvg } from "@resvg/resvg-js";
import satori from "satori";
import { parse as parseToml } from "smol-toml";
import { decompress } from "wawoff2";
// Design tokens, duplicated from apps/site/src/styles/tokens.css's dark
// palette — OG images always render dark regardless of the viewer's theme.
const COLORS = {
bg: "#0d0d0b",
text: "#ece7db",
muted: "#8e897b",
accent: "#ff6b45",
border: "rgba(236, 231, 219, 0.12)",
};
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
const contentDir = path.join(root, "content");
const outDir = path.join(root, "apps", "site", "public", "images", "og");
const pnpmDir = path.join(root, "node_modules", ".pnpm");
const FRONTMATTER_RE = /^\+\+\+\r?\n([\s\S]*?)\r?\n\+\+\+\r?\n?([\s\S]*)$/;
function walk(dir) {
return fs
.readdir(dir, { withFileTypes: true })
.then((entries) =>
Promise.all(
entries.map((entry) => {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) return walk(full);
return entry.isFile() && entry.name.endsWith(".md") ? [full] : [];
}),
),
)
.then((lists) => lists.flat());
}
function slugFor(typeDir, file) {
const rel = path.relative(typeDir, file).split(path.sep).join("/");
return rel.endsWith("/index.md")
? rel.slice(0, -"/index.md".length)
: rel.slice(0, -".md".length);
}
async function readEntries(typeDir) {
if (
!(await fs.access(typeDir).then(
() => true,
() => false,
))
) {
return [];
}
const files = await walk(typeDir);
const entries = await Promise.all(
files.map(async (file) => {
const raw = await fs.readFile(file, "utf8");
const match = raw.match(FRONTMATTER_RE);
if (!match) return null;
return { slug: slugFor(typeDir, file), frontmatter: parseToml(match[1]) };
}),
);
return entries.filter(Boolean);
}
async function findPnpmPackageDir(prefix) {
const entries = await fs.readdir(pnpmDir);
const match = entries.find((e) => e.startsWith(prefix));
if (!match) throw new Error(`Could not find pnpm package matching ${prefix}`);
return path.join(pnpmDir, match, "node_modules");
}
async function loadFont(absPath) {
const woff2 = await fs.readFile(absPath);
const ttf = await decompress(woff2);
return Buffer.from(ttf);
}
function h(type, props, ...children) {
return {
type,
props: {
...props,
children: children.flat().filter((c) => c !== null && c !== undefined),
},
};
}
function formatDate(date) {
if (!date) return undefined;
// smol-toml parses TOML dates into Date objects directly.
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
});
}
function card({ kicker, title, meta, tags }) {
const stampTag = tags[0];
const footerTags =
tags.length > 4 ? `${tags.slice(0, 4).join(" · ")} ⋯` : tags.join(" · ");
const titleSize = title.length > 70 ? 46 : title.length > 45 ? 54 : 64;
return h(
"div",
{
style: {
width: "1200px",
height: "630px",
display: "flex",
backgroundColor: COLORS.bg,
color: COLORS.text,
fontFamily: "Newsreader",
},
},
h(
"div",
{
style: {
flex: 1,
margin: "40px",
border: `1px solid ${COLORS.border}`,
borderRadius: "6px",
padding: "48px 56px",
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
},
},
h(
"div",
{
style: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "flex-start",
},
},
h(
"div",
{
style: {
display: "flex",
fontFamily: "JetBrains Mono",
fontWeight: 400,
fontSize: "22px",
color: COLORS.muted,
letterSpacing: "2px",
},
},
`ANDWATI.COM · ${kicker}`,
),
stampTag
? h(
"div",
{
style: {
display: "flex",
border: `2px solid ${COLORS.accent}`,
borderRadius: "4px",
padding: "8px 16px",
color: COLORS.accent,
fontFamily: "JetBrains Mono",
fontWeight: 700,
fontSize: "20px",
letterSpacing: "2px",
textTransform: "uppercase",
transform: "rotate(3deg)",
},
},
stampTag,
)
: null,
),
h(
"div",
{
style: {
display: "flex",
fontFamily: "Fraunces",
fontWeight: 600,
fontSize: `${titleSize}px`,
lineHeight: 1.15,
letterSpacing: "-1px",
color: COLORS.text,
overflow: "hidden",
},
},
title,
),
h(
"div",
{
style: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
borderTop: `1px solid ${COLORS.border}`,
paddingTop: "24px",
},
},
h(
"div",
{
style: {
display: "flex",
fontFamily: "JetBrains Mono",
fontWeight: 400,
fontSize: "20px",
color: COLORS.muted,
letterSpacing: "1px",
},
},
meta ?? "",
),
h(
"div",
{
style: {
display: "flex",
fontFamily: "JetBrains Mono",
fontWeight: 400,
fontSize: "20px",
color: COLORS.muted,
letterSpacing: "1px",
},
},
footerTags,
),
),
),
);
}
function writingsCard(entry) {
return card({
kicker: "WRITINGS",
title: entry.frontmatter.title,
meta: formatDate(entry.frontmatter.date),
tags: entry.frontmatter.taxonomies?.tags ?? [],
});
}
function portfolioCard(entry) {
return card({
kicker: "PORTFOLIO",
title: entry.frontmatter.title,
meta: entry.frontmatter.role ?? entry.frontmatter.outcome,
tags: entry.frontmatter.taxonomies?.tags ?? [],
});
}
function bookshelfCard(entry) {
const authors = entry.frontmatter.authors ?? [];
return card({
kicker: "BOOKSHELF",
title: entry.frontmatter.title,
meta: authors.length ? authors.join(", ") : undefined,
tags: entry.frontmatter.taxonomies?.tags ?? [],
});
}
// Static-weight builds, not the variable fonts the site ships — satori's
// opentype.js parser can't read these packages' fvar table (throws on the
// axis-name lookup), so a fixed weight per family is loaded instead.
const jetbrainsMonoDir = await findPnpmPackageDir("@fontsource+jetbrains-mono");
const fraunceDir = await findPnpmPackageDir("@fontsource+fraunces");
const newsreaderDir = await findPnpmPackageDir("@fontsource+newsreader");
const fonts = [
{
name: "Fraunces",
data: await loadFont(
path.join(
fraunceDir,
"@fontsource/fraunces/files/fraunces-latin-600-normal.woff2",
),
),
weight: 600,
style: "normal",
},
{
name: "Newsreader",
data: await loadFont(
path.join(
newsreaderDir,
"@fontsource/newsreader/files/newsreader-latin-400-normal.woff2",
),
),
weight: 400,
style: "normal",
},
{
name: "JetBrains Mono",
data: await loadFont(
path.join(
jetbrainsMonoDir,
"@fontsource/jetbrains-mono/files/jetbrains-mono-latin-400-normal.woff2",
),
),
weight: 400,
style: "normal",
},
{
name: "JetBrains Mono",
data: await loadFont(
path.join(
jetbrainsMonoDir,
"@fontsource/jetbrains-mono/files/jetbrains-mono-latin-700-normal.woff2",
),
),
weight: 700,
style: "normal",
},
];
const TYPES = [
{
name: "writings",
buildCard: writingsCard,
isDraft: (e) => e.frontmatter.draft,
},
{
name: "portfolio",
buildCard: portfolioCard,
isDraft: (e) => e.frontmatter.draft,
},
{ name: "bookshelf", buildCard: bookshelfCard, isDraft: () => false },
];
let count = 0;
for (const type of TYPES) {
const typeDir = path.join(contentDir, type.name);
const entries = await readEntries(typeDir);
const typeOutDir = path.join(outDir, type.name);
await fs.mkdir(typeOutDir, { recursive: true });
for (const entry of entries) {
if (!entry.frontmatter.title || type.isDraft(entry)) continue;
const svg = await satori(type.buildCard(entry), {
width: 1200,
height: 630,
fonts,
});
const png = new Resvg(svg).render().asPng();
await fs.writeFile(path.join(typeOutDir, `${entry.slug}.png`), png);
count += 1;
}
}
console.log(
`Generated ${count} OG image${count === 1 ? "" : "s"} in ${path.relative(root, outDir)}/`,
);