Syntax Highlighting Test
Fenced code blocks get highlighted at build time. No JavaScript. A small tokenizer in build.py handles keywords, strings, and comments.
Python
#!/usr/bin/env python3
from pathlib import Path
from datetime import datetime, timezone
def parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---\n"):
return {}, text
try:
end = text.index("\n---\n", 4)
except ValueError:
return {}, text
meta = {}
for line in text[4:end].splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip()
return meta, text[end + 5:]
if __name__ == "__main__":
for path in sorted(Path("content/posts").glob("*.md"), reverse=True):
meta, _ = parse_frontmatter(path.read_text())
print(f"{meta.get('date', '?')} {meta.get('title', path.stem)}")
Bash
#!/usr/bin/env bash
set -euo pipefail
SITE="lotek.run"
OUT="output"
if [ ! -d "$OUT" ]; then
echo "run build.py first" >&2
exit 1
fi
# rsync to remote, delete files that no longer exist locally
rsync -avz --delete "$OUT/" "user@$SITE:/var/www/html/"
echo "deployed."
Rust
use std::fs;
use std::path::Path;
fn slugify(title: &str) -> String {
title
.to_lowercase()
.chars()
.map(|c| if c.is_alphanumeric() { c } else { '-' })
.collect::<String>()
.trim_matches('-')
.to_string()
}
fn main() {
let posts = Path::new("content/posts");
for entry in fs::read_dir(posts).expect("no posts dir") {
let path = entry.unwrap().path();
if path.extension().map_or(false, |e| e == "md") {
println!("{}", path.display());
}
}
}
TOML
[site]
title = "lotek.run"
url = "https://lotek.run"
desc = "dispatches from the margins"
[build]
posts_dir = "content/posts"
output_dir = "output"
date_format = "%Y-%m-%d"
[author]
name = "unknown"
contact = "find a way"
SQL
-- hypothetical: if this site ever needed a database (it doesn't)
SELECT
slug,
title,
date,
array_length(string_to_array(tags, ','), 1) AS tag_count
FROM posts
WHERE date >= current_date - interval '90 days'
ORDER BY date DESC;