diff --git a/.gitignore b/.gitignore
index c533452a1d..816264d852 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,3 +124,12 @@ Makefile.local
# Built binaries
/gotea
/cgi/gotea-cgi
+
+# Vendored bb build products
+/third_party/bb/bb
+/third_party/bb/src/*.o
+/third_party/bb/build/
+/third_party/bb/dist/
+/third_party/bb/tests/md_test
+/third_party/bb/tests/tmpl_test
+/third_party/bb/tests/theme_test
diff --git a/Makefile b/Makefile
index a3c5823a4c..7bccaa327f 100644
--- a/Makefile
+++ b/Makefile
@@ -489,6 +489,14 @@ test-e2e: playwright frontend backend
.PHONY: build
build: frontend backend ## build everything
+.PHONY: bb
+bb: ## build the vendored bb static site generator
+ $(MAKE) -C third_party/bb
+
+.PHONY: bb-check
+bb-check: bb ## run bb's own test suite
+ $(MAKE) -C third_party/bb test
+
.PHONY: frontend
frontend: $(FRONTEND_DEST) ## build frontend files
diff --git a/third_party/bb/Makefile b/third_party/bb/Makefile
new file mode 100644
index 0000000000..8ae759c94f
--- /dev/null
+++ b/third_party/bb/Makefile
@@ -0,0 +1,80 @@
+# bb — C99 static site generator
+# POSIX make. No GNU-isms. Builds ./bb, then `make` in a project dir runs it.
+
+CC ?= cc
+CFLAGS ?= -O2 -std=c99 -Wall -Wextra -pedantic
+LDFLAGS ?=
+
+# Compiled-in share dir (installed layout). Override: make PREFIX=/usr
+BB_SHAREDIR_FLAG = -DBB_SHAREDIR=\"$(SHAREDIR)\"
+
+# Render shell for layouts (override: make SHELL=/bin/bash)
+BB_SHELL_FLAG = -DBB_SHELL=\"$(SHELL)\"
+
+SRC = src/main.c src/markdown.c src/template.c src/theme.c src/config.c src/strbuf.c src/post.c src/serve.c
+OBJ = $(SRC:.c=.o)
+
+PREFIX ?= /usr/local
+BINDIR = $(PREFIX)/bin
+SHAREDIR = $(PREFIX)/share/bb
+MANDIR = $(PREFIX)/share/man
+
+# Theme for project builds (override: make THEME=kde11)
+THEME ?= oli7
+
+all: bb
+
+bb: $(OBJ)
+ $(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(BB_SHAREDIR_FLAG) $(BB_SHELL_FLAG) -c -o $@ $<
+
+# Project targets (run inside a bb project dir)
+# make THEME=oli7 -> dist/
+build:
+ ./bb build --theme $(THEME)
+
+clean:
+ rm -f bb $(OBJ)
+
+# Unit tests: markdown parser + sh templating engine
+TEST_CFLAGS = -std=c99 -Wall -Wextra -pedantic -Isrc
+
+test: bb
+ $(CC) $(TEST_CFLAGS) tests/md_test.c src/markdown.c src/strbuf.c -o tests/md_test
+ $(CC) $(TEST_CFLAGS) tests/tmpl_test.c src/template.c src/strbuf.c -o tests/tmpl_test
+ $(CC) $(TEST_CFLAGS) tests/theme_test.c src/theme.c src/config.c src/strbuf.c -o tests/theme_test
+ ./tests/md_test
+ ./tests/tmpl_test
+ ./tests/theme_test
+ @command -v curl >/dev/null && sh tests/serve_test.sh || echo "serve_test: skipped (no curl)"
+
+install: bb
+ mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(SHAREDIR) $(DESTDIR)$(MANDIR)/man1
+ cp bb $(DESTDIR)$(BINDIR)/bb
+ cp -r share/layouts $(DESTDIR)$(SHAREDIR)/
+ cp -r share/themes $(DESTDIR)$(SHAREDIR)/
+ cp -r share/fonts $(DESTDIR)$(SHAREDIR)/
+ cp -r share/bb/lib $(DESTDIR)$(SHAREDIR)/
+ cp man/bb.1 $(DESTDIR)$(MANDIR)/man1/bb.1
+
+uninstall:
+ rm -f $(DESTDIR)$(BINDIR)/bb
+ rm -rf $(DESTDIR)$(SHAREDIR)
+ rm -f $(DESTDIR)$(MANDIR)/man1/bb.1
+
+# man page -> HTML dump for the website (www/overlay/docs/). Uses man2html
+# if present, else pandoc. bb build copies overlay/ verbatim into dist/.
+man-html:
+ mkdir -p www/overlay/docs
+ @if command -v man2html >/dev/null 2>&1; then \
+ man2html man/bb.1 > www/overlay/docs/bb.1.html; \
+ elif command -v pandoc >/dev/null 2>&1; then \
+ pandoc -s -t html man/bb.1 -o www/overlay/docs/bb.1.html; \
+ else \
+ echo "error: need man2html or pandoc to build www/overlay/docs/bb.1.html"; \
+ exit 1; \
+ fi
+
+.PHONY: all build clean test install uninstall man-html
diff --git a/third_party/bb/NOTICE b/third_party/bb/NOTICE
new file mode 100644
index 0000000000..f02fb9d4b2
--- /dev/null
+++ b/third_party/bb/NOTICE
@@ -0,0 +1,28 @@
+bb — C99 static site generator
+==============================
+
+Vendored from https://git.hiddenbox.org/lotherk/bb-c
+Upstream commit: f5373fb (www/README/man: Texte neu, ehrlich zu KI-Entstehung)
+
+bb is MIT-licensed. The upstream source tree carries the same grant in its
+README; this notice preserves it for the vendored copy.
+
+Copyright (c) 2026 The bb Authors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/third_party/bb/README.md b/third_party/bb/README.md
new file mode 100644
index 0000000000..079e63cc06
--- /dev/null
+++ b/third_party/bb/README.md
@@ -0,0 +1,108 @@
+# bb
+
+A content-first static site generator written in pure C99 + POSIX `/bin/sh`.
+Write Markdown, run `make`, get a complete static site. No framework, no
+JavaScript in the output, no runtime backend. Developed on Linux against
+C99 and POSIX; the output is plain HTML 4.01 and reads fine in `lynx`.
+
+bb was written together with an AI (Claude). I steered and tested, the model
+wrote most of the code.
+
+## Why
+
+bb does one thing: turn Markdown into a static site. The layout is a plain
+`/bin/sh` script, so there is no template engine to learn. The output is
+HTML 4.01 with one stylesheet.
+
+## Build
+
+```sh
+make # builds ./bb
+make install # installs to /usr/local (override: make PREFIX=/usr)
+```
+
+Requires a C99 compiler and POSIX make. No external dependencies.
+
+## Quick start
+
+```sh
+bb init my-site
+cd my-site
+make # builds into dist/
+lynx dist/index.html
+```
+
+`bb init` scaffolds a project with `site.conf`, `pages/`, `posts/`, and a
+`Makefile`. `make` runs `bb build` with the default theme.
+
+## Usage
+
+```sh
+bb init [dir] Scaffold a new project
+bb new post "Title" Create a new blog post (opens $EDITOR if set)
+bb new page "Title" Create a new page (opens $EDITOR if set)
+bb build [--theme N] Build current project into dist/
+bb serve [--port N] Preview dist/ at http://127.0.0.1:8000/
+bb theme check Report theme contrast problems
+```
+
+## Project structure
+
+```
+my-site/
+ site.conf # site title, description, optional font
+ pages/ # pages (index.md -> /, about.md -> /about/)
+ posts/ # blog posts (YYYY-MM-DD-slug.md)
+ overlay/ # optional: files copied verbatim into dist/
+ pages.de/ # optional: translations, built into dist/de/
+ posts.pt/ # optional: translated posts, built into dist/pt/blog/
+ Makefile # runs bb build
+ dist/ # output (generated, wiped on every build)
+```
+
+Pages opt into the nav bar with `menu: true`, `menuLabel` and `menuOrder`
+in their frontmatter. `overlay/` is for images, `robots.txt`, a favicon:
+anything that must survive `dist/` being rebuilt from scratch. See
+`man bb` for the details of i18n and the templating helpers.
+
+## Layouts
+
+The layout is a POSIX `/bin/sh` script at `share/layouts/layout.sh`. BB
+sources `share/bb/lib/bb.sh` transparently before running it, so the
+`bb_*` helpers are always available — and the layout can override them.
+
+See the [Templating Library](https://git.hiddenbox.org/lotherk/bb) docs
+for `bb_nav`, `bb_content`, `bb_each_post`, `bb_each_page`, and more.
+
+## Themes
+
+A theme is a small file of design tokens (`bg`, `text`, `link`, `heading`,
+... plus `frame = bevel` for raised/sunken Motif and Windows 95 looks) in
+`share/themes/*.conf`. Pick one with `make THEME=breeze` or
+`bb build --theme breeze`. Only `bg` is required; the rest is derived.
+
+bb makes every theme readable: colours are moved towards black or white
+until they reach WCAG AA contrast, so imported palettes cannot produce
+unreadable pages. `bb theme check` shows what it changed.
+
+70+ themes ship, imported from real desktop toolkits with the scripts in
+`scripts/` (CDE `.dp`, KDE `.colors`, GTK2 `gtk-color-scheme`), plus `oli7`,
+the one custom theme, extracted from a photo of Konrad's son and wife. See
+`man bb` (THEME FORMAT) for the full token list.
+
+## Fonts
+
+Set `font = monospace` (or `sans`, `serif`) in `site.conf` to bundle a
+font from `share/fonts/` into `dist/assets/fonts/` and emit `@font-face`
+CSS. If unset, the OS default is used.
+
+## Install layout
+
+`make install` copies the binary to `$(PREFIX)/bin` and the layouts,
+themes, fonts, and `lib/bb.sh` to `$(PREFIX)/share/bb`. The binary finds
+its share dir via the compiled-in `BB_SHAREDIR` (default
+`/usr/local/share/bb`), falling back to `./share` in the source tree.
+
+## License
+
+MIT.
diff --git a/third_party/bb/man/bb.1 b/third_party/bb/man/bb.1
new file mode 100644
index 0000000000..61160d8d37
--- /dev/null
+++ b/third_party/bb/man/bb.1
@@ -0,0 +1,465 @@
+.TH BB 1 "September 2026" "bb 1.0" "User Commands"
+.SH NAME
+bb \- a content-first static site generator in C99 and POSIX sh
+.SH SYNOPSIS
+.B bb
+.RI [ command ]
+.RI [ options ]
+.SH DESCRIPTION
+.B bb
+turns Markdown into a static website. You write pages and posts as plain
+Markdown files, run
+.BR bb " build"
+(or
+.BR make ),
+and get a complete static site in
+.BR dist/ .
+.PP
+The output is a single pure HTML 4.01 version. There is no JavaScript, no
+runtime backend, and no template engine: layouts are plain POSIX
+.B /bin/sh
+scripts that emit HTML. The result renders in
+.B lynx
+and in current browsers.
+.B bb
+is written in C99 and POSIX and is developed on Linux.
+.PP
+.B bb
+is written in C99 and has no dependencies beyond a C99 compiler and POSIX
+.BR make .
+.SH COMMANDS
+.TP
+.B bb init
+.RI [ dir ]
+Scaffold a new project. Creates
+.BR site.conf ,
+.BR pages/ ,
+.BR posts/ ,
+and a
+.BR Makefile .
+If
+.I dir
+is given, the project is created there; otherwise in the current directory.
+.TP
+.B bb new post
+.RI "[" title ]
+Create a new blog post in
+.BR posts/ ,
+named
+.IR YYYY-MM-DD-slug.md .
+Opens
+.B $EDITOR
+if set.
+.TP
+.B bb new page
+.RI "[" title ]
+Create a new page in
+.BR pages/ .
+Opens
+.B $EDITOR
+if set.
+.TP
+.B bb build
+.RI [ --theme " " name ]
+Build the current project into
+.BR dist/ .
+The
+.B --theme
+option selects a color palette from
+.BR share/themes/ .
+.TP
+.B bb serve
+.RI [ --port " " n ]
+.RI [ --bind " " addr ]
+.RI [ --dir " " path ]
+Serve the built site over HTTP for local preview. Defaults:
+.B 127.0.0.1
+port
+.B 8000
+directory
+.BR dist/ .
+GET and HEAD only; requests are confined to the directory (symlinks that
+leave it are refused). It does not rebuild; run
+.B bb build
+first. Not intended for exposure to the internet.
+.TP
+.B bb theme check
+.RI [ --strict ]
+.RI [ name " ..." ]
+Report which theme palettes are not readable as written and what bb adjusts
+at build time (all themes without a name). With
+.B --strict
+the exit status is 1 if anything needed fixing.
+.TP
+.B bb help
+Print usage.
+.SH PROJECT STRUCTURE
+A bb project is a plain directory:
+.PP
+.nf
+.RS
+my-site/
+ site.conf site title, description, optional font
+ pages/ pages (index.md -> /, about.md -> /about/)
+ posts/ blog posts (YYYY-MM-DD-slug.md)
+ overlay/ extra files copied verbatim into dist/ (optional)
+ pages.de/ german pages, built into dist/de/ (optional, i18n)
+ posts.pt/ portuguese posts, built into dist/pt/blog/ (optional, i18n)
+ Makefile runs bb build
+ dist/ output (generated)
+.RE
+.fi
+.SH OVERLAY
+.B bb build
+always rebuilds
+.B dist/
+from scratch, so stale files never linger. Any files you want deployed
+verbatim (images, extra HTML, a favicon, a custom
+.BR robots.txt )
+go in
+.BR overlay/ ;
+they are copied 1:1 into
+.B dist/
+after the build, overwriting generated files of the same name.
+.SH I18N
+Translations live in sibling directories named after the language:
+.BR pages.de/ ,
+.BR posts.pt/ ,
+and so on. Each one builds into
+.BR dist//
+with the same routes as the default language
+.RB ( pages.de/index.md -> dist/de/index.html ,
+.BR posts.pt/2026-01-01-ola.md " -> " dist/pt/blog/ola/ ).
+The layout receives
+.B LANG
+(the current language, empty for the default),
+.BR BB_LANGS
+(space-separated list of all translation languages) and
+.BR HTML_LANG_ATTR
+(which the default layout uses for
+.BR ),
+and the default layout renders a text-language switcher automatically.
+A site may translate only part of its content; untranslated sections
+simply do not exist under
+.BR dist// .
+The default language can be marked with a
+.B pages.
+symlink pointing at
+.BR pages/ ,
+for example
+.BR "ln -s pages pages.en" .
+The marked language builds no separate tree; instead root pages get
+.B lang=""
+in the
+.B
+tag and the switcher links the default language to
+.B /
+instead of
+.BR // .
+.SH CONFIGURATION
+.B site.conf
+is a plain
+.IR "key = value"
+file. Recognized keys:
+.TP
+.B title
+The site title, shown in the header and page titles.
+.TP
+.B description
+A short site description, used in the header and RSS feed.
+.TP
+.B theme
+The theme palette used when
+.B --theme
+is not given (e.g.
+.BR oli7 ).
+The command-line option takes precedence.
+.TP
+.B base_url
+The site's absolute URL. When set,
+.B bb
+also writes
+.BR sitemap.xml .
+.TP
+.B font
+Optional. One of
+.BR monospace ,
+.BR sans ,
+.BR serif .
+When set, the matching font from
+.B share/fonts/
+is bundled into
+.B dist/assets/fonts/
+and an
+.B @font-face
+rule is emitted; the font applies to body text. When unset, the OS default
+is used.
+.TP
+.BR font.h1 , " font.h2, " font.h3 ", " font.h4 ", " font.h5 ", " font.h6 ", " font.code
+Optional per-element font overrides. The value is either a generic CSS
+family
+.RB ( monospace ,
+.BR sans ,
+.BR serif ,
+or a full
+.B font-family
+stack like
+.BR "\"Georgia, serif\"" )
+or the name of a bundled font in
+.BR share/fonts/ ,
+which is then copied into
+.B dist/assets/fonts/
+with an
+.B @font-face
+rule and applied to that element only:
+.B font.h1
+targets
+.BR h1 ,
+.B font.code
+targets
+.BR "pre, code" .
+Element overrides take precedence over the base
+.BR font .
+.SH FRONTMATTER
+Each page and post may start with a YAML frontmatter block between two
+.B ---
+lines. Any key becomes an environment variable prefixed with
+.B FM_
+(uppercased) in the layout. For example:
+.PP
+.nf
+.RS
+---
+title: My Post
+author: Konrad
+robots: Disallow: /private/
+---
+.RE
+.fi
+.PP
+makes
+.BR $FM_TITLE ,
+.BR $FM_AUTHOR ,
+and
+.BR $FM_ROBOTS
+available to the layout. The frontmatter is fully custom: you can add any
+key and read it in the layout.
+.SH LAYOUTS
+The layout is a POSIX
+.B /bin/sh
+script at
+.BR share/layouts/layout.sh .
+Before it runs,
+.B bb
+sources
+.B share/bb/lib/bb.sh
+transparently, so the
+.B bb_*
+helper functions are always available and can be overridden by the layout.
+.PP
+The layout receives these environment variables:
+.TP
+.B SITE_TITLE
+Site title.
+.TP
+.B SITE_DESC
+Site description.
+.TP
+.B PAGE_TITLE
+Current page or post title.
+.TP
+.B CONTENT_FILE
+Path to the rendered Markdown content (a temp file).
+.TP
+.B THEME
+Selected theme name.
+.TP
+.B NAV
+Pipe-separated nav:
+.IR "Label|/route/|Label2|/route2/" .
+.TP
+.B BB_POSTS_FILE
+Path to a pipe-separated post list
+.RI ( slug|title|date|url
+per line).
+.TP
+.B BB_PAGES_FILE
+Path to a pipe-separated page list
+.RI ( label|url
+per line).
+.TP
+.B BB_LIB
+Path to
+.BR lib/bb.sh .
+.TP
+.B FONT_CSS
+.B @font-face
+CSS if a font is configured, else empty.
+.TP
+.B FM_*
+Every frontmatter key, uppercased.
+.PP
+Theme colors are also passed as environment variables
+.RB ( BG ,
+.BR TEXT ,
+.BR LINK ,
+.BR BORDER ,
+.BR HEADING ,
+.BR MUTED ,
+.BR CODEBG ).
+.SH TEMPLATING LIBRARY
+.B lib/bb.sh
+provides helper functions:
+.TP
+.B bb_nav
+Emit the nav menu from
+.BR $NAV .
+Only pages with
+.B menu: true
+frontmatter appear (index.md as "Home");
+.B menuLabel
+overrides the label,
+.B menuOrder
+sorts.
+.TP
+.B bb_content
+Emit the rendered Markdown content (reads
+.BR $CONTENT_FILE ).
+.TP
+.B bb_each_post
+.I block
+Run a block for each post. Inside the block,
+.BR $slug ,
+.BR $title ,
+.BR $date ,
+and
+.BR $url
+are set.
+.TP
+.B bb_each_page
+.I block
+Run a block for each page. Inside the block,
+.BR $label
+and
+.BR $url
+are set.
+.TP
+.B bb_post_list
+Emit a
+.B
+of posts.
+.TP
+.B bb_page_list
+Emit a
+.B
+of pages.
+.SH THEMES
+A theme is a file of design tokens,
+.IR "key = value" ,
+in
+.BR share/themes/.conf .
+Select one with
+.BR "bb build --theme " name
+or
+.BR "make THEME=" name ,
+or set
+.B theme
+in
+.BR site.conf
+(the command-line option wins).
+.SH THEME FORMAT
+Colours are
+.B #rgb
+or
+.BR #rrggbb .
+Only
+.B bg
+is required; everything else is derived when missing.
+.TP
+.B bg text
+Page background and body text.
+.TP
+.B link link.visited
+Link colours. Derived from
+.B text
+if missing.
+.TP
+.B heading muted
+Headings and secondary text (blockquotes, footer).
+.TP
+.B border codebg
+Rules and table borders; background of code blocks.
+.TP
+.B title.bg title.fg
+Header bar colours, used by
+.BR "frame = bevel" .
+.TP
+.B select.bg select.fg
+Text selection.
+.TP
+.B light dark
+Highlight and shadow edges for bevels. Derived from
+.BR bg .
+.TP
+.B frame
+.B flat
+(default) or
+.BR bevel :
+the header becomes a raised title bar and code blocks are sunken, using
+plain CSS borders, so it works in old browsers.
+.TP
+.B frame.width
+Bevel border width (default
+.BR 2px ).
+.TP
+.B font font.code font.h1 ... font.h6
+Font stacks, e.g.
+.BR "font = Georgia, serif" .
+A bare name that matches a bundled font in
+.B share/fonts/
+is copied into the site.
+.PP
+At build time bb normalizes every theme: missing tokens are derived, and
+text, links, headings, muted text, code text and the title bar are moved
+towards black or white (keeping their hue) until they reach WCAG AA
+contrast: 4.5:1, or 3:1 for headings. Imported palettes therefore stay
+readable whatever their source. The stylesheet comes from the template
+.BR share/layouts/theme.css ,
+in which
+.B {{token}}
+is replaced by the normalized value.
+.PP
+Importers that map other formats onto these tokens live in
+.BR scripts/ :
+.BR import-cde.sh " (CDE " .dp ),
+.BR import-kde.sh " (KDE " .colors )
+and
+.BR import-gtk2.sh " (GTK2 " gtk-color-scheme ).
+.SH FILES
+.TP
+.B share/layouts/layout.sh
+The layout script.
+.TP
+.B share/bb/lib/bb.sh
+The templating library.
+.TP
+.B share/themes/*.conf
+Theme palettes.
+.TP
+.B share/fonts/
+Bundled fonts.
+.SH ENVIRONMENT
+.TP
+.B EDITOR
+Opened by
+.B bb new
+to edit a new post or page.
+.SH EXIT STATUS
+.B bb
+exits 0 on success and non-zero on error.
+.SH SEE ALSO
+.BR make (1),
+.BR sh (1),
+.BR lynx (1)
+.SH LICENSE
+MIT.
diff --git a/third_party/bb/share/bb/lib/bb.sh b/third_party/bb/share/bb/lib/bb.sh
new file mode 100644
index 0000000000..8870829d4e
--- /dev/null
+++ b/third_party/bb/share/bb/lib/bb.sh
@@ -0,0 +1,92 @@
+# lib/bb.sh — templating helpers for bb layouts.
+# Sourced into every layout script. Provides functions to iterate over
+# posts and pages, render the nav, and emit common HTML.
+#
+# Data comes in as env vars set by bb:
+# BB_POSTS_FILE path to a file, one post per line: slug|title|date|url
+# BB_PAGES_FILE path to a file, one page per line: label|url
+# NAV pipe-separated nav: Label|/route/|Label2|/route2/
+# BB_PREFIX relative prefix ("../" * page depth) for root-relative links
+#
+# All URLs in the data files are root-relative (start with "/"). bb_*
+# helpers prepend $BB_PREFIX so links work no matter where the site is
+# deployed (/, /bb/, ...). Override bb_prefix() to change the behaviour.
+
+# Resolve a root-relative URL to a page-relative one.
+bb_url() {
+ case "$1" in
+ /*)
+ rel="${1#/}"
+ if [ -z "$rel" ]; then
+ # "/" -> the site root, relative to this page
+ printf '%s.' "$BB_PREFIX"
+ else
+ printf '%s%s' "$BB_PREFIX" "$rel"
+ fi
+ ;;
+ *) printf '%s' "$1" ;;
+ esac
+}
+
+# Emit the nav as HTML links (pipe-separated NAV).
+bb_nav() {
+ [ -n "$NAV" ] || return 0
+ oldifs="$IFS"
+ IFS='|'
+ set -- $NAV
+ IFS="$oldifs"
+ first=1
+ while [ $# -ge 2 ]; do
+ if [ $first -eq 1 ]; then
+ printf '%s ' "$(bb_url "$2")" "$1"
+ first=0
+ else
+ printf ' | %s ' "$(bb_url "$2")" "$1"
+ fi
+ shift 2
+ done
+ printf '\n'
+}
+
+# Run a block for each post. Usage:
+# bb_each_post 'echo "$title "'
+# Inside the block: $slug, $title, $date, $url are set ($url is page-relative).
+bb_each_post() {
+ [ -n "$BB_POSTS_FILE" ] && [ -f "$BB_POSTS_FILE" ] || return 0
+ while IFS='|' read -r slug title date url; do
+ [ -n "$slug" ] || continue
+ url="$(bb_url "$url")"
+ eval "$1"
+ done < "$BB_POSTS_FILE"
+}
+
+# Run a block for each page. Usage:
+# bb_each_page 'echo "$label "'
+# Inside the block: $label, $url are set ($url is page-relative).
+bb_each_page() {
+ [ -n "$BB_PAGES_FILE" ] && [ -f "$BB_PAGES_FILE" ] || return 0
+ while IFS='|' read -r label url; do
+ [ -n "$label" ] || continue
+ url="$(bb_url "$url")"
+ eval "$1"
+ done < "$BB_PAGES_FILE"
+}
+
+# Emit a post list as .
+bb_post_list() {
+ echo ''
+ bb_each_post 'printf "%s (%s) \n" "$url" "$title" "$date"'
+ echo ' '
+}
+
+# Emit a page list as .
+bb_page_list() {
+ echo ''
+ bb_each_page 'printf "%s \n" "$url" "$label"'
+ echo ' '
+}
+
+# Inject the rendered Markdown content.
+bb_content() {
+ [ -n "$CONTENT_FILE" ] && [ -f "$CONTENT_FILE" ] && cat "$CONTENT_FILE"
+}
diff --git a/third_party/bb/share/fonts/monospace.ttf b/third_party/bb/share/fonts/monospace.ttf
new file mode 100644
index 0000000000..9f75ef0a84
Binary files /dev/null and b/third_party/bb/share/fonts/monospace.ttf differ
diff --git a/third_party/bb/share/fonts/sans.ttf b/third_party/bb/share/fonts/sans.ttf
new file mode 100644
index 0000000000..cd832a2e51
Binary files /dev/null and b/third_party/bb/share/fonts/sans.ttf differ
diff --git a/third_party/bb/share/fonts/serif.ttf b/third_party/bb/share/fonts/serif.ttf
new file mode 100644
index 0000000000..ae0933a868
Binary files /dev/null and b/third_party/bb/share/fonts/serif.ttf differ
diff --git a/third_party/bb/share/layouts/layout.sh b/third_party/bb/share/layouts/layout.sh
new file mode 100644
index 0000000000..698886744c
--- /dev/null
+++ b/third_party/bb/share/layouts/layout.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# layout.sh — single pure HTML 4.01 layout, works in lynx/links and old browsers.
+# No JS, no CSS-grid, no light/dark split. One output, everywhere.
+# Theme colors come in as env vars (BG, TEXT, LINK, BORDER, HEADING, MUTED, CODEBG).
+# lib/bb.sh is sourced transparently by bb before this script runs, so the
+# bb_* helpers (bb_nav, bb_content, bb_each_post) are already available
+# and can be overridden here.
+
+# language switcher: BB_LANGS="de pt" -> one entry per language, pointing at
+# that language's home page via bb_url (respects BB_PREFIX). The default
+# language (BB_LANG_DEFAULT, marked by a pages. symlink to pages/)
+# links to / instead of //. The current language is shown unlinked.
+# Rendered only when the site really has two or more languages.
+bb_langs() {
+ out=""
+ for l in $BB_LANGS; do
+ # current language: shown unlinked
+ if [ "$l" = "$LANG" ] || { [ -z "$LANG" ] && [ "$l" = "$BB_LANG_DEFAULT" ]; }; then
+ if [ -n "$out" ]; then out="$out | "; fi
+ out="$out$l"
+ continue
+ fi
+ if [ "$l" = "$BB_LANG_DEFAULT" ]; then href="$(bb_url /)"; else href="$(bb_url /$l/)"; fi
+ if [ -n "$out" ]; then out="$out | "; fi
+ out="$out$l "
+ done
+ [ -n "$out" ] && printf '%s' "$out"
+}
+
+cat <
+
+
+
+ $PAGE_TITLE · $SITE_TITLE
+
+
+
+
+
+
+
+$(bb_content)
+
+
+
+
+EOF
\ No newline at end of file
diff --git a/third_party/bb/share/layouts/theme.css b/third_party/bb/share/layouts/theme.css
new file mode 100644
index 0000000000..f4075744c6
--- /dev/null
+++ b/third_party/bb/share/layouts/theme.css
@@ -0,0 +1,19 @@
+/* theme.css -- stylesheet template. bb fills the double-brace tokens from
+ * the normalized theme and writes dist/css/style.css (man bb, THEME FORMAT).
+ * Plain CSS 1/2: no variables, no JS. */
+body { background: {{bg}}; color: {{text}}; font-family: {{font.body.css}}; margin: 2em auto; max-width: 760px; padding: 0 1em; }
+a { color: {{link}}; text-decoration: underline; }
+a:visited { color: {{link.visited}}; }
+a:hover, a:focus { color: {{heading}}; }
+h1, h2, h3 { color: {{heading}}; }
+::selection { background: {{select.bg}}; color: {{select.fg}}; }
+pre, code { font-family: {{font.code.css}}; background: {{codebg}}; color: {{text}}; padding: 0.2em; }
+pre { padding: 1em; overflow-x: auto; border-style: solid; border-width: {{pre.bw}}; border-color: {{pre.bc}}; }
+table { border-collapse: collapse; }
+th, td { border: 1px solid {{border}}; padding: 0.4em 0.8em; }
+blockquote { border-left: 4px solid {{border}}; margin-left: 0; padding-left: 1em; color: {{muted}}; }
+.site-header { background: {{hdr.bg}}; color: {{hdr.text}}; border-style: solid; border-width: {{hdr.bw}}; border-color: {{hdr.bc}}; padding: {{hdr.pad}}; margin-bottom: 1.5em; }
+.site-header h1 { color: {{hdr.h1}}; }
+.site-header a, .site-header a:visited { color: {{hdr.link}}; text-decoration: underline; }
+.site-header a:hover, .site-header a:focus { color: {{hdr.h1}}; }
+.site-footer { border-top: 1px solid {{border}}; margin-top: 2em; color: {{muted}}; font-size: 0.9em; }
diff --git a/third_party/bb/share/themes/adwaita-dark.conf b/third_party/bb/share/themes/adwaita-dark.conf
new file mode 100644
index 0000000000..1f778d0091
--- /dev/null
+++ b/third_party/bb/share/themes/adwaita-dark.conf
@@ -0,0 +1,11 @@
+# Adwaita-dark -- GTK2 colour scheme, imported by scripts/import-gtk2.sh
+bg = #33393b
+text = #eeeeec
+codebg = #232729
+link = #215d9c
+heading = #215d9c
+title.bg = #215d9c
+select.bg = #215d9c
+title.fg = #ffffff
+select.fg = #ffffff
+frame = flat
diff --git a/third_party/bb/share/themes/adwaita.conf b/third_party/bb/share/themes/adwaita.conf
new file mode 100644
index 0000000000..f59d8bf96f
--- /dev/null
+++ b/third_party/bb/share/themes/adwaita.conf
@@ -0,0 +1,11 @@
+# Adwaita -- GTK2 colour scheme, imported by scripts/import-gtk2.sh
+bg = #e8e8e7
+text = #2e3436
+codebg = #ffffff
+link = #4a90d9
+heading = #4a90d9
+title.bg = #4a90d9
+select.bg = #4a90d9
+title.fg = #ffffff
+select.fg = #ffffff
+frame = flat
diff --git a/third_party/bb/share/themes/b00merang-dark.conf b/third_party/bb/share/themes/b00merang-dark.conf
new file mode 100644
index 0000000000..d5efb18bab
--- /dev/null
+++ b/third_party/bb/share/themes/b00merang-dark.conf
@@ -0,0 +1,12 @@
+# b00merang-dark — imported from Node-bb
+bg = #252525
+text = #f2f2f2
+link = #798fcb
+border = #999999
+heading = #f2f2f2
+muted = #f2f2f2
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = 'Bold', sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/breeze-classic.conf b/third_party/bb/share/themes/breeze-classic.conf
new file mode 100644
index 0000000000..acd0350742
--- /dev/null
+++ b/third_party/bb/share/themes/breeze-classic.conf
@@ -0,0 +1,17 @@
+# BreezeClassic -- KDE colour scheme, imported by scripts/import-kde.sh
+bg = #eff0f1
+text = #232627
+link = #2980b9
+link.visited = #7f8c8d
+muted = #7f8c8d
+codebg = #eff0f1
+heading = #3daee9
+select.bg = #3daee9
+select.fg = #fcfcfc
+title.bg = #475057
+title.fg = #fcfcfc
+frame = flat
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/breeze-dark.conf b/third_party/bb/share/themes/breeze-dark.conf
new file mode 100644
index 0000000000..08d7deda05
--- /dev/null
+++ b/third_party/bb/share/themes/breeze-dark.conf
@@ -0,0 +1,17 @@
+# BreezeDark -- KDE colour scheme, imported by scripts/import-kde.sh
+bg = #202326
+text = #fcfcfc
+link = #1d99f3
+link.visited = #9b59b6
+muted = #a1a9b1
+codebg = #1d1f22
+heading = #3daee9
+select.bg = #3daee9
+select.fg = #fcfcfc
+title.bg = #272c31
+title.fg = #fcfcfc
+frame = flat
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/breeze-light.conf b/third_party/bb/share/themes/breeze-light.conf
new file mode 100644
index 0000000000..0155c1225e
--- /dev/null
+++ b/third_party/bb/share/themes/breeze-light.conf
@@ -0,0 +1,17 @@
+# BreezeLight -- KDE colour scheme, imported by scripts/import-kde.sh
+bg = #eff0f1
+text = #232629
+link = #2980b9
+link.visited = #9b59b6
+muted = #707d8a
+codebg = #f7f7f7
+heading = #3daee9
+select.bg = #3daee9
+select.fg = #ffffff
+title.bg = #e3e5e7
+title.fg = #232629
+frame = flat
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/breeze.conf b/third_party/bb/share/themes/breeze.conf
new file mode 100644
index 0000000000..e68b3d4329
--- /dev/null
+++ b/third_party/bb/share/themes/breeze.conf
@@ -0,0 +1,12 @@
+# breeze — imported from Node-bb
+bg = #eff0f1
+text = #232629
+link = #236e9f
+border = #999999
+heading = #232629
+muted = #232629
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/cde-alpine.conf b/third_party/bb/share/themes/cde-alpine.conf
new file mode 100644
index 0000000000..a47ce51a8c
--- /dev/null
+++ b/third_party/bb/share/themes/cde-alpine.conf
@@ -0,0 +1,9 @@
+# cde-alpine -- CDE palette Alpine, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #bf9279
+link = #afbffb
+heading = #bfc0c5
+border = #78aab8
+codebg = #bfc0c5
+title.bg = #afbffb
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-arizona.conf b/third_party/bb/share/themes/cde-arizona.conf
new file mode 100644
index 0000000000..42aeeee943
--- /dev/null
+++ b/third_party/bb/share/themes/cde-arizona.conf
@@ -0,0 +1,9 @@
+# cde-arizona -- CDE palette Arizona, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #c37d79
+link = #ffab78
+heading = #84545f
+border = #a86b79
+codebg = #885770
+title.bg = #ffab78
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-beigerose.conf b/third_party/bb/share/themes/cde-beigerose.conf
new file mode 100644
index 0000000000..e046a8d4a9
--- /dev/null
+++ b/third_party/bb/share/themes/cde-beigerose.conf
@@ -0,0 +1,9 @@
+# cde-beigerose -- CDE palette BeigeRose, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #919191
+link = #618888
+heading = #90b0ac
+border = #d1c0ae
+codebg = #f0eceb
+title.bg = #618888
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-black.conf b/third_party/bb/share/themes/cde-black.conf
new file mode 100644
index 0000000000..ed2c0d8428
--- /dev/null
+++ b/third_party/bb/share/themes/cde-black.conf
@@ -0,0 +1,9 @@
+# cde-black -- CDE palette Black, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #000000
+link = #000000
+heading = #000000
+border = #000000
+codebg = #000000
+title.bg = #000000
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-blackwhite.conf b/third_party/bb/share/themes/cde-blackwhite.conf
new file mode 100644
index 0000000000..fa7e0be56a
--- /dev/null
+++ b/third_party/bb/share/themes/cde-blackwhite.conf
@@ -0,0 +1,9 @@
+# cde-blackwhite -- CDE palette BlackWhite, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #000000
+link = #000000
+heading = #000000
+border = #ffffff
+codebg = #000000
+title.bg = #000000
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-broica.conf b/third_party/bb/share/themes/cde-broica.conf
new file mode 100644
index 0000000000..06d3d150e8
--- /dev/null
+++ b/third_party/bb/share/themes/cde-broica.conf
@@ -0,0 +1,9 @@
+# cde-broica -- CDE palette Broica, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #c6b2a8
+link = #eda870
+heading = #93abbf
+border = #999999
+codebg = #686f82
+title.bg = #eda870
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-cabernet.conf b/third_party/bb/share/themes/cde-cabernet.conf
new file mode 100644
index 0000000000..6b3e5e72b7
--- /dev/null
+++ b/third_party/bb/share/themes/cde-cabernet.conf
@@ -0,0 +1,9 @@
+# cde-cabernet -- CDE palette Cabernet, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #b65c71
+link = #d88775
+heading = #495c65
+border = #638a7a
+codebg = #4b5e61
+title.bg = #d88775
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-camouflage.conf b/third_party/bb/share/themes/cde-camouflage.conf
new file mode 100644
index 0000000000..58ade3217c
--- /dev/null
+++ b/third_party/bb/share/themes/cde-camouflage.conf
@@ -0,0 +1,9 @@
+# cde-camouflage -- CDE palette Camouflage, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #8e8e77
+link = #acbeb4
+heading = #4e6b65
+border = #6e7d76
+codebg = #82829b
+title.bg = #acbeb4
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-charcoal.conf b/third_party/bb/share/themes/cde-charcoal.conf
new file mode 100644
index 0000000000..8e7c4f2a83
--- /dev/null
+++ b/third_party/bb/share/themes/cde-charcoal.conf
@@ -0,0 +1,9 @@
+# cde-charcoal -- CDE palette Charcoal, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #828585
+link = #87b4b0
+heading = #af9696
+border = #767279
+codebg = #896d6d
+title.bg = #87b4b0
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-chocolate.conf b/third_party/bb/share/themes/cde-chocolate.conf
new file mode 100644
index 0000000000..75f7ed3ec6
--- /dev/null
+++ b/third_party/bb/share/themes/cde-chocolate.conf
@@ -0,0 +1,9 @@
+# cde-chocolate -- CDE palette Chocolate, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #b9a0a0
+link = #a9a9ff
+heading = #9696b9
+border = #708c8d
+codebg = #967878
+title.bg = #a9a9ff
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-cinnamon.conf b/third_party/bb/share/themes/cde-cinnamon.conf
new file mode 100644
index 0000000000..45fd8d8db9
--- /dev/null
+++ b/third_party/bb/share/themes/cde-cinnamon.conf
@@ -0,0 +1,9 @@
+# cde-cinnamon -- CDE palette Cinnamon, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #9b6862
+link = #b14b50
+heading = #78695d
+border = #926866
+codebg = #836960
+title.bg = #b14b50
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-clay.conf b/third_party/bb/share/themes/cde-clay.conf
new file mode 100644
index 0000000000..47dedb2479
--- /dev/null
+++ b/third_party/bb/share/themes/cde-clay.conf
@@ -0,0 +1,9 @@
+# cde-clay -- CDE palette Clay, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #af9191
+link = #ffaaaa
+heading = #2f8b8d
+border = #968282
+codebg = #8c6464
+title.bg = #ffaaaa
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-crimson.conf b/third_party/bb/share/themes/cde-crimson.conf
new file mode 100644
index 0000000000..a125a3bda9
--- /dev/null
+++ b/third_party/bb/share/themes/cde-crimson.conf
@@ -0,0 +1,9 @@
+# cde-crimson -- CDE palette Crimson, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #68a6a0
+link = #b24d7a
+heading = #9793b5
+border = #aeb2c3
+codebg = #fff7e9
+title.bg = #b24d7a
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-darkgold.conf b/third_party/bb/share/themes/cde-darkgold.conf
new file mode 100644
index 0000000000..50fa0c1f05
--- /dev/null
+++ b/third_party/bb/share/themes/cde-darkgold.conf
@@ -0,0 +1,9 @@
+# cde-darkgold -- CDE palette DarkGold, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #a8a8a8
+link = #b89663
+heading = #6b94b2
+border = #7a7c7f
+codebg = #ffffe2
+title.bg = #b89663
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-default.conf b/third_party/bb/share/themes/cde-default.conf
new file mode 100644
index 0000000000..21f03dd5e4
--- /dev/null
+++ b/third_party/bb/share/themes/cde-default.conf
@@ -0,0 +1,9 @@
+# cde-default -- CDE palette Default, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #c6b2a8
+link = #eda870
+heading = #93abbf
+border = #999999
+codebg = #686f82
+title.bg = #eda870
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-delphinium.conf b/third_party/bb/share/themes/cde-delphinium.conf
new file mode 100644
index 0000000000..00f4c128a9
--- /dev/null
+++ b/third_party/bb/share/themes/cde-delphinium.conf
@@ -0,0 +1,9 @@
+# cde-delphinium -- CDE palette Delphinium, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #78b4be
+link = #85c4ed
+heading = #90a0be
+border = #c8c8c8
+codebg = #ffffe6
+title.bg = #85c4ed
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-desert.conf b/third_party/bb/share/themes/cde-desert.conf
new file mode 100644
index 0000000000..3c7b446258
--- /dev/null
+++ b/third_party/bb/share/themes/cde-desert.conf
@@ -0,0 +1,9 @@
+# cde-desert -- CDE palette Desert, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #9faeb5
+link = #e5b793
+heading = #c4929b
+border = #c2bba7
+codebg = #fdfdfa
+title.bg = #e5b793
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-golden.conf b/third_party/bb/share/themes/cde-golden.conf
new file mode 100644
index 0000000000..1b7e12c244
--- /dev/null
+++ b/third_party/bb/share/themes/cde-golden.conf
@@ -0,0 +1,9 @@
+# cde-golden -- CDE palette Golden, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #757ca6
+link = #faad49
+heading = #b1705f
+border = #4d648d
+codebg = #47634f
+title.bg = #faad49
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-grass.conf b/third_party/bb/share/themes/cde-grass.conf
new file mode 100644
index 0000000000..321f9022a9
--- /dev/null
+++ b/third_party/bb/share/themes/cde-grass.conf
@@ -0,0 +1,9 @@
+# cde-grass -- CDE palette Grass, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #a4a9aa
+link = #d4c77d
+heading = #829694
+border = #bec6b7
+codebg = #e2f3e2
+title.bg = #d4c77d
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-grayscale.conf b/third_party/bb/share/themes/cde-grayscale.conf
new file mode 100644
index 0000000000..00898cdf5e
--- /dev/null
+++ b/third_party/bb/share/themes/cde-grayscale.conf
@@ -0,0 +1,9 @@
+# cde-grayscale -- CDE palette GrayScale, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #bcbcbc
+link = #c3c3c3
+heading = #939393
+border = #787777
+codebg = #949493
+title.bg = #c3c3c3
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-lilac.conf b/third_party/bb/share/themes/cde-lilac.conf
new file mode 100644
index 0000000000..384080fde0
--- /dev/null
+++ b/third_party/bb/share/themes/cde-lilac.conf
@@ -0,0 +1,9 @@
+# cde-lilac -- CDE palette Lilac, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #a5a5ac
+link = #d3d178
+heading = #917e9f
+border = #a5a5ac
+codebg = #c3c3c9
+title.bg = #d3d178
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-makroslate.conf b/third_party/bb/share/themes/cde-makroslate.conf
new file mode 100644
index 0000000000..537e9c2b90
--- /dev/null
+++ b/third_party/bb/share/themes/cde-makroslate.conf
@@ -0,0 +1,9 @@
+# cde-makroslate -- CDE palette MakroSlate, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #8ea8b8
+link = #181f26
+heading = #f8fcff
+border = #2b3a44
+codebg = #607888
+title.bg = #181f26
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-mustard.conf b/third_party/bb/share/themes/cde-mustard.conf
new file mode 100644
index 0000000000..0a9609c431
--- /dev/null
+++ b/third_party/bb/share/themes/cde-mustard.conf
@@ -0,0 +1,9 @@
+# cde-mustard -- CDE palette Mustard, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #887ca3
+link = #d5802e
+heading = #2a6889
+border = #b75f5f
+codebg = #5c6a58
+title.bg = #d5802e
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-neptune.conf b/third_party/bb/share/themes/cde-neptune.conf
new file mode 100644
index 0000000000..24fa5d6a6a
--- /dev/null
+++ b/third_party/bb/share/themes/cde-neptune.conf
@@ -0,0 +1,9 @@
+# cde-neptune -- CDE palette Neptune, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #637e95
+link = #a2e5c6
+heading = #616d8e
+border = #3f938d
+codebg = #7889a5
+title.bg = #a2e5c6
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-northernsky.conf b/third_party/bb/share/themes/cde-northernsky.conf
new file mode 100644
index 0000000000..04a9c1c77d
--- /dev/null
+++ b/third_party/bb/share/themes/cde-northernsky.conf
@@ -0,0 +1,9 @@
+# cde-northernsky -- CDE palette NorthernSky, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #41525c
+link = #a47591
+heading = #3d407c
+border = #1b5d6c
+codebg = #00577a
+title.bg = #a47591
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-nutmeg.conf b/third_party/bb/share/themes/cde-nutmeg.conf
new file mode 100644
index 0000000000..221df38d72
--- /dev/null
+++ b/third_party/bb/share/themes/cde-nutmeg.conf
@@ -0,0 +1,9 @@
+# cde-nutmeg -- CDE palette Nutmeg, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #b39c8f
+link = #cec2bb
+heading = #457293
+border = #256593
+codebg = #cdb2a6
+title.bg = #cec2bb
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-olive.conf b/third_party/bb/share/themes/cde-olive.conf
new file mode 100644
index 0000000000..285640b872
--- /dev/null
+++ b/third_party/bb/share/themes/cde-olive.conf
@@ -0,0 +1,9 @@
+# cde-olive -- CDE palette Olive, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #cdbdaa
+link = #83835a
+heading = #9a919a
+border = #c3c3b9
+codebg = #cec2b8
+title.bg = #83835a
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-orchid.conf b/third_party/bb/share/themes/cde-orchid.conf
new file mode 100644
index 0000000000..8d000e1f93
--- /dev/null
+++ b/third_party/bb/share/themes/cde-orchid.conf
@@ -0,0 +1,9 @@
+# cde-orchid -- CDE palette Orchid, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #9bbed7
+link = #b9b9ff
+heading = #b0b0bf
+border = #9b9bb9
+codebg = #8282ab
+title.bg = #b9b9ff
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-pbnj.conf b/third_party/bb/share/themes/cde-pbnj.conf
new file mode 100644
index 0000000000..2bcea219d7
--- /dev/null
+++ b/third_party/bb/share/themes/cde-pbnj.conf
@@ -0,0 +1,9 @@
+# cde-pbnj -- CDE palette PBNJ, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #c69076
+link = #b65c61
+heading = #ebd7bf
+border = #d9c1b2
+codebg = #f1e3d2
+title.bg = #b65c61
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-sand.conf b/third_party/bb/share/themes/cde-sand.conf
new file mode 100644
index 0000000000..b974092480
--- /dev/null
+++ b/third_party/bb/share/themes/cde-sand.conf
@@ -0,0 +1,9 @@
+# cde-sand -- CDE palette Sand, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #af8181
+link = #eabe93
+heading = #969696
+border = #c7afaf
+codebg = #d4d4da
+title.bg = #eabe93
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-santafe.conf b/third_party/bb/share/themes/cde-santafe.conf
new file mode 100644
index 0000000000..05c8e6fe91
--- /dev/null
+++ b/third_party/bb/share/themes/cde-santafe.conf
@@ -0,0 +1,9 @@
+# cde-santafe -- CDE palette SantaFe, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #83a5b6
+link = #ef9d9d
+heading = #9c9992
+border = #7eabab
+codebg = #ceaf9a
+title.bg = #ef9d9d
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-savannah.conf b/third_party/bb/share/themes/cde-savannah.conf
new file mode 100644
index 0000000000..31fd2b2783
--- /dev/null
+++ b/third_party/bb/share/themes/cde-savannah.conf
@@ -0,0 +1,9 @@
+# cde-savannah -- CDE palette Savannah, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #c6b2a8
+link = #da9a68
+heading = #93abbf
+border = #b4aa94
+codebg = #d2bfa8
+title.bg = #da9a68
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-seafoam.conf b/third_party/bb/share/themes/cde-seafoam.conf
new file mode 100644
index 0000000000..04210c2d17
--- /dev/null
+++ b/third_party/bb/share/themes/cde-seafoam.conf
@@ -0,0 +1,9 @@
+# cde-seafoam -- CDE palette SeaFoam, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #afbfba
+link = #aacbdb
+heading = #c8ada0
+border = #a7a8a7
+codebg = #97b0b2
+title.bg = #aacbdb
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-skyred.conf b/third_party/bb/share/themes/cde-skyred.conf
new file mode 100644
index 0000000000..0138df910c
--- /dev/null
+++ b/third_party/bb/share/themes/cde-skyred.conf
@@ -0,0 +1,9 @@
+# cde-skyred -- CDE palette SkyRed, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #6e91aa
+link = #cc686f
+heading = #5e84b9
+border = #afc0c2
+codebg = #e1ebe1
+title.bg = #cc686f
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-softblue.conf b/third_party/bb/share/themes/cde-softblue.conf
new file mode 100644
index 0000000000..6b8daba097
--- /dev/null
+++ b/third_party/bb/share/themes/cde-softblue.conf
@@ -0,0 +1,9 @@
+# cde-softblue -- CDE palette SoftBlue, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #94d5df
+link = #7fa9eb
+heading = #5d7cb8
+border = #76a99c
+codebg = #6c6c6c
+title.bg = #7fa9eb
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-southwest.conf b/third_party/bb/share/themes/cde-southwest.conf
new file mode 100644
index 0000000000..4e5a951bcc
--- /dev/null
+++ b/third_party/bb/share/themes/cde-southwest.conf
@@ -0,0 +1,9 @@
+# cde-southwest -- CDE palette SouthWest, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #b86f4b
+link = #ff7d79
+heading = #989ca8
+border = #a97561
+codebg = #b18885
+title.bg = #ff7d79
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-summer.conf b/third_party/bb/share/themes/cde-summer.conf
new file mode 100644
index 0000000000..9bba3ffdce
--- /dev/null
+++ b/third_party/bb/share/themes/cde-summer.conf
@@ -0,0 +1,9 @@
+# cde-summer -- CDE palette Summer, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #86eae7
+link = #ff5664
+heading = #bcc5db
+border = #ffd690
+codebg = #ffffff
+title.bg = #ff5664
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-tundra.conf b/third_party/bb/share/themes/cde-tundra.conf
new file mode 100644
index 0000000000..8d1dbc6b5b
--- /dev/null
+++ b/third_party/bb/share/themes/cde-tundra.conf
@@ -0,0 +1,9 @@
+# cde-tundra -- CDE palette Tundra, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #859680
+link = #f1bc7f
+heading = #837e75
+border = #a59680
+codebg = #767e63
+title.bg = #f1bc7f
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-urchin.conf b/third_party/bb/share/themes/cde-urchin.conf
new file mode 100644
index 0000000000..09378e66fb
--- /dev/null
+++ b/third_party/bb/share/themes/cde-urchin.conf
@@ -0,0 +1,9 @@
+# cde-urchin -- CDE palette Urchin, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #3792a2
+link = #d5a591
+heading = #328392
+border = #0f7c7a
+codebg = #0c6864
+title.bg = #d5a591
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-wheat.conf b/third_party/bb/share/themes/cde-wheat.conf
new file mode 100644
index 0000000000..f52f2f993c
--- /dev/null
+++ b/third_party/bb/share/themes/cde-wheat.conf
@@ -0,0 +1,9 @@
+# cde-wheat -- CDE palette Wheat, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #94d5df
+link = #d1a57a
+heading = #5d7cb8
+border = #dbc291
+codebg = #bfc0c5
+title.bg = #d1a57a
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-white.conf b/third_party/bb/share/themes/cde-white.conf
new file mode 100644
index 0000000000..61e401b5dd
--- /dev/null
+++ b/third_party/bb/share/themes/cde-white.conf
@@ -0,0 +1,9 @@
+# cde-white -- CDE palette White, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #ffffff
+link = #ffffff
+heading = #ffffff
+border = #ffffff
+codebg = #ffffff
+title.bg = #ffffff
+frame = bevel
diff --git a/third_party/bb/share/themes/cde-whiteblack.conf b/third_party/bb/share/themes/cde-whiteblack.conf
new file mode 100644
index 0000000000..4f65f76d9c
--- /dev/null
+++ b/third_party/bb/share/themes/cde-whiteblack.conf
@@ -0,0 +1,9 @@
+# cde-whiteblack -- CDE palette WhiteBlack, imported by scripts/import-cde.sh
+# Slots: 1 active frame, 2 inactive frame, 4 text areas, 5 background, 8 front panel.
+bg = #ffffff
+link = #ffffff
+heading = #ffffff
+border = #000000
+codebg = #ffffff
+title.bg = #ffffff
+frame = bevel
diff --git a/third_party/bb/share/themes/cde.conf b/third_party/bb/share/themes/cde.conf
new file mode 100644
index 0000000000..3b7b0f6179
--- /dev/null
+++ b/third_party/bb/share/themes/cde.conf
@@ -0,0 +1,14 @@
+# cde — imported from Node-bb
+bg = #3a5564
+text = #f2f5f7
+link = #9fd3ff
+border = #5b6f7e
+heading = #f2f5f7
+muted = #f2f5f7
+codebg = #5b6f7e
+
+# original fonts (from Node-bb theme.css)
+font = 'IBM Plex Sans', 'Lucida Grande', 'Tahoma', system-ui, sans-serif
+font.code = 'IBM Plex Mono', 'Lucida Console', monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/cepheus.conf b/third_party/bb/share/themes/cepheus.conf
new file mode 100644
index 0000000000..690b763557
--- /dev/null
+++ b/third_party/bb/share/themes/cepheus.conf
@@ -0,0 +1,12 @@
+# cepheus — imported from Node-bb
+bg = #f2f6f3
+text = #16231d
+link = #0f6f8a
+border = #bfd0c7
+heading = #16231d
+muted = #16231d
+codebg = #bfd0c7
+
+# original fonts (from Node-bb theme.css)
+font = "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Times New Roman", serif
+font.code = "SFMono-Regular", "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace
diff --git a/third_party/bb/share/themes/clearlooks.conf b/third_party/bb/share/themes/clearlooks.conf
new file mode 100644
index 0000000000..b4af5ccf91
--- /dev/null
+++ b/third_party/bb/share/themes/clearlooks.conf
@@ -0,0 +1,12 @@
+# clearlooks — imported from Node-bb
+bg = #c9c9c8
+text = #535353
+link = #0000cc
+border = #999999
+heading = #535353
+muted = #535353
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/crux.conf b/third_party/bb/share/themes/crux.conf
new file mode 100644
index 0000000000..6068ff2dbc
--- /dev/null
+++ b/third_party/bb/share/themes/crux.conf
@@ -0,0 +1,12 @@
+# crux — imported from Node-bb
+bg = #f5f5b5
+text = #6b6b6b
+link = #0000cc
+border = #999999
+heading = #6b6b6b
+muted = #6b6b6b
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/ember-tide.conf b/third_party/bb/share/themes/ember-tide.conf
new file mode 100644
index 0000000000..4a419e55b6
--- /dev/null
+++ b/third_party/bb/share/themes/ember-tide.conf
@@ -0,0 +1,12 @@
+# ember-tide — imported from Node-bb
+bg = #f3eee7
+text = #2d241f
+link = #8a4b28
+border = #d7c9ba
+heading = #2d241f
+muted = #2d241f
+codebg = #d7c9ba
+
+# original fonts (from Node-bb theme.css)
+font = Georgia, "Times New Roman", Times, serif
+font.code = "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace
diff --git a/third_party/bb/share/themes/fantome.conf b/third_party/bb/share/themes/fantome.conf
new file mode 100644
index 0000000000..1528219126
--- /dev/null
+++ b/third_party/bb/share/themes/fantome.conf
@@ -0,0 +1,12 @@
+# fantome — imported from Node-bb
+bg = #2f343f
+text = #d8dee8
+link = #d08b91
+border = #999999
+heading = #d8dee8
+muted = #d8dee8
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/fvwm-default.conf b/third_party/bb/share/themes/fvwm-default.conf
new file mode 100644
index 0000000000..b293d8b98c
--- /dev/null
+++ b/third_party/bb/share/themes/fvwm-default.conf
@@ -0,0 +1,14 @@
+# fvwm-default — imported from Node-bb
+bg = #003c3c
+text = #ffffff
+link = #9595e9
+border = #999999
+heading = #ffffff
+muted = #ffffff
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/fvwm.conf b/third_party/bb/share/themes/fvwm.conf
new file mode 100644
index 0000000000..2466356041
--- /dev/null
+++ b/third_party/bb/share/themes/fvwm.conf
@@ -0,0 +1,14 @@
+# fvwm — imported from Node-bb
+bg = #7e8a92
+text = #111111
+link = #003399
+border = #6f6f6f
+heading = #111111
+muted = #111111
+codebg = #6f6f6f
+
+# original fonts (from Node-bb theme.css)
+font = 'IBM Plex Sans', 'Tahoma', 'MS Sans Serif', system-ui, sans-serif
+font.code = 'IBM Plex Mono', 'Lucida Console', monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/industrial.conf b/third_party/bb/share/themes/industrial.conf
new file mode 100644
index 0000000000..49b7a97bcb
--- /dev/null
+++ b/third_party/bb/share/themes/industrial.conf
@@ -0,0 +1,12 @@
+# industrial — imported from Node-bb
+bg = #d9d9d9
+text = #5c5c5c
+link = #0000cc
+border = #999999
+heading = #5c5c5c
+muted = #5c5c5c
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/irix5.conf b/third_party/bb/share/themes/irix5.conf
new file mode 100644
index 0000000000..f9c814fd08
--- /dev/null
+++ b/third_party/bb/share/themes/irix5.conf
@@ -0,0 +1,14 @@
+# irix5 — imported from Node-bb
+bg = #9fb8d9
+text = #000000
+link = #0000aa
+border = #5f5f66
+heading = #000000
+muted = #000000
+codebg = #5f5f66
+
+# original fonts (from Node-bb theme.css)
+font = "Trebuchet MS", "Helvetica Neue", Arial, sans-serif
+font.code = "Courier New", "Lucida Console", monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/irixium.conf b/third_party/bb/share/themes/irixium.conf
new file mode 100644
index 0000000000..def037a963
--- /dev/null
+++ b/third_party/bb/share/themes/irixium.conf
@@ -0,0 +1,14 @@
+# irixium — imported from Node-bb
+bg = #c1c1c1
+text = #000000
+link = #0000ff
+border = #999999
+heading = #000000
+muted = #000000
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/iwanttobelieve.conf b/third_party/bb/share/themes/iwanttobelieve.conf
new file mode 100644
index 0000000000..8ee423fdea
--- /dev/null
+++ b/third_party/bb/share/themes/iwanttobelieve.conf
@@ -0,0 +1,12 @@
+# iwanttobelieve — imported from Node-bb
+bg = #f6f3ef
+text = #31281f
+link = #5a4937
+border = #c7bcaf
+heading = #31281f
+muted = #31281f
+codebg = #c7bcaf
+
+# original fonts (from Node-bb theme.css)
+font = "Arial Narrow", Arial, "Helvetica Neue", Helvetica, sans-serif
+font.code = "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace
diff --git a/third_party/bb/share/themes/kde-whitesur-dark.conf b/third_party/bb/share/themes/kde-whitesur-dark.conf
new file mode 100644
index 0000000000..e48f31b141
--- /dev/null
+++ b/third_party/bb/share/themes/kde-whitesur-dark.conf
@@ -0,0 +1,12 @@
+# kde-whitesur-dark — imported from Node-bb
+bg = #363636
+text = #fcfcfc
+link = #849cf6
+border = #999999
+heading = #fcfcfc
+muted = #fcfcfc
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/kde-whitesur.conf b/third_party/bb/share/themes/kde-whitesur.conf
new file mode 100644
index 0000000000..b1d151b9da
--- /dev/null
+++ b/third_party/bb/share/themes/kde-whitesur.conf
@@ -0,0 +1,12 @@
+# kde-whitesur — imported from Node-bb
+bg = #ffffff
+text = #242424
+link = #277ab0
+border = #999999
+heading = #242424
+muted = #242424
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/kde11.conf b/third_party/bb/share/themes/kde11.conf
new file mode 100644
index 0000000000..85f9ef928d
--- /dev/null
+++ b/third_party/bb/share/themes/kde11.conf
@@ -0,0 +1,14 @@
+# kde11 — imported from Node-bb
+bg = #c0c0c0
+text = #000000
+link = #0000cc
+border = #999999
+heading = #000000
+muted = #000000
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/lumiere.conf b/third_party/bb/share/themes/lumiere.conf
new file mode 100644
index 0000000000..de06254c0b
--- /dev/null
+++ b/third_party/bb/share/themes/lumiere.conf
@@ -0,0 +1,12 @@
+# lumiere — imported from Node-bb
+bg = #ffffff
+text = #474c57
+link = #317b92
+border = #999999
+heading = #474c57
+muted = #474c57
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/macos9.conf b/third_party/bb/share/themes/macos9.conf
new file mode 100644
index 0000000000..c181f8f7eb
--- /dev/null
+++ b/third_party/bb/share/themes/macos9.conf
@@ -0,0 +1,14 @@
+# macos9 — imported from Node-bb
+bg = #c9c8e8
+text = #111111
+link = #0000cc
+border = #8f8fb0
+heading = #111111
+muted = #111111
+codebg = #8f8fb0
+
+# original fonts (from Node-bb theme.css)
+font = "Charcoal", "Chicago", "Geneva", "MS Sans Serif", "Segoe UI", sans-serif
+font.code = "Monaco", "Courier New", monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/mist.conf b/third_party/bb/share/themes/mist.conf
new file mode 100644
index 0000000000..7e56367c18
--- /dev/null
+++ b/third_party/bb/share/themes/mist.conf
@@ -0,0 +1,12 @@
+# mist — imported from Node-bb
+bg = #eaeaea
+text = #666666
+link = #0000cc
+border = #999999
+heading = #666666
+muted = #666666
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/nashville-gruvbox.conf b/third_party/bb/share/themes/nashville-gruvbox.conf
new file mode 100644
index 0000000000..d71f24a2a3
--- /dev/null
+++ b/third_party/bb/share/themes/nashville-gruvbox.conf
@@ -0,0 +1,12 @@
+# nashville-gruvbox — imported from Node-bb
+bg = #282828
+text = #ebdbb2
+link = #dc7430
+border = #282828
+heading = #ebdbb2
+muted = #ebdbb2
+codebg = #282828
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/nashville-solarized.conf b/third_party/bb/share/themes/nashville-solarized.conf
new file mode 100644
index 0000000000..21ee448fa0
--- /dev/null
+++ b/third_party/bb/share/themes/nashville-solarized.conf
@@ -0,0 +1,12 @@
+# nashville-solarized — imported from Node-bb
+bg = #073642
+text = #eee8d5
+link = #e37aac
+border = #073642
+heading = #eee8d5
+muted = #eee8d5
+codebg = #073642
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/oli7.conf b/third_party/bb/share/themes/oli7.conf
new file mode 100644
index 0000000000..dc901c4dee
--- /dev/null
+++ b/third_party/bb/share/themes/oli7.conf
@@ -0,0 +1,13 @@
+# oli7 — extracted from a photo of my son and my wife.
+# The warmth and love of that image, turned into a color palette.
+bg = #faf5ec
+text = #3f3128
+link = #5f7f98
+border = #d8c3ad
+heading = #2f5fbf
+muted = #7c6758
+codebg = #f1e5d6
+
+# original fonts (from Node-bb theme.css)
+font = ui-serif, Georgia, Cambria, "Times New Roman", Times, serif
+font.code = ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace
diff --git a/third_party/bb/share/themes/qnx6.conf b/third_party/bb/share/themes/qnx6.conf
new file mode 100644
index 0000000000..435e88e921
--- /dev/null
+++ b/third_party/bb/share/themes/qnx6.conf
@@ -0,0 +1,14 @@
+# qnx6 — imported from Node-bb
+bg = #d5d4e3
+text = #1f1f22
+link = #8f5e12
+border = #8d8d96
+heading = #1f1f22
+muted = #1f1f22
+codebg = #8d8d96
+
+# original fonts (from Node-bb theme.css)
+font = Georgia, "Times New Roman", Times, serif
+font.code = "Courier New", Courier, monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/redmond.conf b/third_party/bb/share/themes/redmond.conf
new file mode 100644
index 0000000000..4880e63609
--- /dev/null
+++ b/third_party/bb/share/themes/redmond.conf
@@ -0,0 +1,14 @@
+# redmond — imported from Node-bb
+bg = #e6e6e6
+text = #666666
+link = #0000cc
+border = #999999
+heading = #666666
+muted = #666666
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = system-ui, -apple-system, sans-serif
+font.code = ui-monospace, monospace
+
+frame = bevel
diff --git a/third_party/bb/share/themes/sunset.conf b/third_party/bb/share/themes/sunset.conf
new file mode 100644
index 0000000000..e83035845e
--- /dev/null
+++ b/third_party/bb/share/themes/sunset.conf
@@ -0,0 +1,12 @@
+# sunset — imported from Node-bb
+bg = #f6ead9
+text = #253240
+link = #8a4f17
+border = #d6b890
+heading = #253240
+muted = #253240
+codebg = #d6b890
+
+# original fonts (from Node-bb theme.css)
+font = Georgia, "Times New Roman", Times, serif
+font.code = "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace
diff --git a/third_party/bb/share/themes/thinice.conf b/third_party/bb/share/themes/thinice.conf
new file mode 100644
index 0000000000..f9e6064925
--- /dev/null
+++ b/third_party/bb/share/themes/thinice.conf
@@ -0,0 +1,12 @@
+# thinice — imported from Node-bb
+bg = #c1c1cc
+text = #4f4f4f
+link = #0000cc
+border = #999999
+heading = #4f4f4f
+muted = #4f4f4f
+codebg = #999999
+
+# original fonts (from Node-bb theme.css)
+font = 'Sans', sans-serif
+font.code = ui-monospace, monospace
diff --git a/third_party/bb/share/themes/whitesur.conf b/third_party/bb/share/themes/whitesur.conf
new file mode 100644
index 0000000000..662f26b130
--- /dev/null
+++ b/third_party/bb/share/themes/whitesur.conf
@@ -0,0 +1,12 @@
+# whitesur — imported from Node-bb
+bg = #eef2f7
+text = #1b2430
+link = #0860f2
+border = #cfd7e6
+heading = #1b2430
+muted = #1b2430
+codebg = #cfd7e6
+
+# original fonts (from Node-bb theme.css)
+font = 'SF Pro Text', 'San Francisco', 'Helvetica Neue', 'Lucida Grande', 'Segoe UI', system-ui, sans-serif
+font.code = 'SFMono-Regular', 'Menlo', 'JetBrains Mono', ui-monospace, monospace
diff --git a/third_party/bb/src/bb.h b/third_party/bb/src/bb.h
new file mode 100644
index 0000000000..fdd6f114ea
--- /dev/null
+++ b/third_party/bb/src/bb.h
@@ -0,0 +1,84 @@
+/* bb.h — shared declarations for the bb C99 static site generator */
+#ifndef BB_H
+#define BB_H
+
+/* Enable POSIX extensions (strdup, getline, etc.) under strict C99 */
+#define _POSIX_C_SOURCE 200809L
+
+#include
+#include
+
+/* Growable string buffer */
+typedef struct {
+ char *data;
+ size_t len;
+ size_t cap;
+} strbuf;
+
+void sb_init(strbuf *sb);
+void sb_free(strbuf *sb);
+void sb_append(strbuf *sb, const char *s);
+void sb_append_n(strbuf *sb, const char *s, size_t n);
+void sb_append_char(strbuf *sb, char c);
+void sb_printf(strbuf *sb, const char *fmt, ...);
+
+/* HTML escaping */
+void html_escape(strbuf *out, const char *s);
+
+/* Markdown -> HTML, streamed from FILE* to FILE* (never buffered in RAM) */
+void markdown_to_html(FILE *out, FILE *in, const char *prefix);
+
+/* config: simple key=value lines, # comments, blank lines skipped */
+typedef struct {
+ char **keys;
+ char **vals;
+ size_t count;
+ size_t cap;
+} config;
+void config_init(config *c);
+void config_free(config *c);
+int config_load(config *c, const char *path);
+const char *config_get(const config *c, const char *key);
+int config_add(config *c, const char *key, const char *val);
+int config_set(config *c, const char *key, const char *val); /* replace or add */
+
+/* Themes (theme.c). A theme is a config of design tokens (see man bb,
+ * "THEME FORMAT"). theme_normalize() fills in missing tokens, enforces
+ * readable contrast and adds the computed tokens the CSS template uses; the
+ * adjustments it made are appended to `report` (may be NULL). */
+double theme_contrast(const char *fg, const char *bg); /* WCAG ratio, <0 on bad colour */
+void theme_normalize(config *t, strbuf *report);
+void theme_render(strbuf *out, const char *template_css, const config *cfg);
+/* Load + normalize one theme file and print a check report to `out`.
+ * Returns the number of adjustments that were necessary (0 = clean). */
+int theme_check_file(const char *path, const char *name, FILE *out);
+
+/* Shell templating: run `sh script` with env vars, stream stdout to `out`.
+ * Returns 0 on success, -1 on failure. */
+int template_run(const char *script_path, char *const envp[], FILE *out);
+
+/* A blog post: date, slug, title, excerpt, content (markdown) */
+typedef struct {
+ char *date; /* YYYY-MM-DD */
+ char *slug; /* from filename */
+ char *title;
+ char *excerpt;
+ char *robots; /* optional robots.txt lines from frontmatter */
+ char *content; /* raw markdown body */
+ config fm; /* all frontmatter key/value pairs */
+} Post;
+
+Post *post_new(void);
+void post_free(Post *p);
+/* Parse a _posts/YYYY-MM-DD-slug.md file. Returns NULL on failure. */
+Post *post_parse(const char *path);
+/* Parse all frontmatter key/value pairs from any .md file into a config.
+ * Returns 0 on success (even if no frontmatter), -1 on read error. */
+int frontmatter_load(const char *path, config *out);
+/* Read a frontmatter value from any .md file (pages too). malloc'd or NULL. */
+char *frontmatter_value(const char *path, const char *key);
+
+/* `bb serve`: preview server for dist/ (serve.c) */
+int cmd_serve(int argc, char **argv);
+
+#endif /* BB_H */
diff --git a/third_party/bb/src/config.c b/third_party/bb/src/config.c
new file mode 100644
index 0000000000..4be49c9698
--- /dev/null
+++ b/third_party/bb/src/config.c
@@ -0,0 +1,101 @@
+/* config.c — simple key=value config parser (INI-ish, no sections) */
+#include "bb.h"
+#include
+#include
+#include
+
+void config_init(config *c) {
+ c->keys = NULL;
+ c->vals = NULL;
+ c->count = 0;
+ c->cap = 0;
+}
+
+void config_free(config *c) {
+ for (size_t i = 0; i < c->count; i++) {
+ free(c->keys[i]);
+ free(c->vals[i]);
+ }
+ free(c->keys);
+ free(c->vals);
+ c->keys = NULL;
+ c->vals = NULL;
+ c->count = 0;
+ c->cap = 0;
+}
+
+int config_add(config *c, const char *key, const char *val) {
+ if (c->count == c->cap) {
+ size_t ncap = c->cap ? c->cap * 2 : 16;
+ char **nk = realloc(c->keys, ncap * sizeof(char *));
+ char **nv = realloc(c->vals, ncap * sizeof(char *));
+ if (!nk || !nv) return -1;
+ c->keys = nk;
+ c->vals = nv;
+ c->cap = ncap;
+ }
+ c->keys[c->count] = strdup(key);
+ c->vals[c->count] = strdup(val);
+ if (!c->keys[c->count] || !c->vals[c->count]) return -1;
+ c->count++;
+ return 0;
+}
+
+int config_load(config *c, const char *path) {
+ FILE *f = fopen(path, "r");
+ if (!f) return -1;
+ char *line = NULL;
+ size_t cap = 0;
+ ssize_t len;
+ while ((len = getline(&line, &cap, f)) != -1) {
+ /* strip newline */
+ while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) line[--len] = '\0';
+ /* trim */
+ char *s = line;
+ while (*s && isspace((unsigned char)*s)) s++;
+ if (*s == '\0' || *s == '#') continue;
+ /* find = */
+ char *eq = strchr(s, '=');
+ if (!eq) continue;
+ *eq = '\0';
+ char *key = s;
+ char *val = eq + 1;
+ /* trim key */
+ char *ke = key + strlen(key) - 1;
+ while (ke >= key && isspace((unsigned char)*ke)) *ke-- = '\0';
+ /* trim val */
+ while (*val && isspace((unsigned char)*val)) val++;
+ char *ve = val + strlen(val) - 1;
+ while (ve >= val && isspace((unsigned char)*ve)) *ve-- = '\0';
+ /* strip quotes */
+ if (*val == '"' && val[strlen(val)-1] == '"') {
+ val[strlen(val)-1] = '\0';
+ val++;
+ }
+ config_add(c, key, val);
+ }
+ free(line);
+ fclose(f);
+ return 0;
+}
+
+/* Replace the value of the first matching key, or add it. */
+int config_set(config *c, const char *key, const char *val) {
+ for (size_t i = 0; i < c->count; i++) {
+ if (strcmp(c->keys[i], key) == 0) {
+ char *nv = strdup(val);
+ if (!nv) return -1;
+ free(c->vals[i]);
+ c->vals[i] = nv;
+ return 0;
+ }
+ }
+ return config_add(c, key, val);
+}
+
+const char *config_get(const config *c, const char *key) {
+ for (size_t i = 0; i < c->count; i++) {
+ if (strcmp(c->keys[i], key) == 0) return c->vals[i];
+ }
+ return NULL;
+}
diff --git a/third_party/bb/src/main.c b/third_party/bb/src/main.c
new file mode 100644
index 0000000000..eb7e5c9538
--- /dev/null
+++ b/third_party/bb/src/main.c
@@ -0,0 +1,1435 @@
+/* main.c — bb CLI: build a project into dist/.
+ * Usage: bb build [--theme NAME] | bb serve [--port N] [--bind ADDR] [--dir DIR]
+ * Reads site.conf, pages/, posts/, renders via /bin/sh layouts.
+ * C99 + POSIX. No fixed-size buffers: all strings grow via strbuf. */
+#include "bb.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static const char *g_theme = "oli7";
+static strbuf g_font_css; /* @font-face CSS, empty = OS default */
+static strbuf g_share; /* dir with layouts/themes/fonts */
+static strbuf g_lib; /* path to lib/bb.sh */
+static strbuf g_tmpdir; /* build temp dir (not /tmp) */
+static strbuf g_langs; /* space-separated language codes (i18n) */
+static const char *g_lang_default; /* default lang via pages. symlink to pages/ (NULL = none) */
+static char *g_font_body; /* body font-family for style.css (NULL = default) */
+static char *g_font_code; /* code font-family for style.css (NULL = monospace) */
+
+static void die(const char *msg) {
+ fprintf(stderr, "bb: %s\n", msg);
+ exit(1);
+}
+
+static int file_exists(const char *path) {
+ struct stat st;
+ return stat(path, &st) == 0;
+}
+
+/* Resolve the share dir. Priority:
+ * 1. compiled-in BB_SHAREDIR (installed layout, e.g. /usr/local/share/bb)
+ * 2. share/ next to the binary (source tree), resolved via argv[0]
+ * 3. ./share (cwd fallback)
+ * Sets g_share (dir with layouts/themes/fonts) and g_lib (lib/bb.sh). */
+static void find_share(const char *argv0) {
+ sb_init(&g_share);
+ sb_init(&g_lib);
+#ifdef BB_SHAREDIR
+ if (file_exists(BB_SHAREDIR)) {
+ sb_append(&g_share, BB_SHAREDIR);
+ sb_printf(&g_lib, "%s/lib/bb.sh", BB_SHAREDIR);
+ return;
+ }
+#endif
+ /* resolve argv[0] to an absolute path: if it contains a slash it is
+ * relative to cwd, else search PATH */
+ char *bin = NULL;
+ if (argv0 && strchr(argv0, '/')) {
+ bin = strdup(argv0);
+ } else if (argv0 && argv0[0]) {
+ const char *path = getenv("PATH");
+ if (path) {
+ strbuf cand; sb_init(&cand);
+ const char *p = path;
+ while (p && *p) {
+ const char *colon = strchr(p, ':');
+ size_t plen = colon ? (size_t)(colon - p) : strlen(p);
+ sb_free(&cand); sb_init(&cand);
+ if (plen > 0) { sb_append_n(&cand, p, plen); sb_append_char(&cand, '/'); }
+ sb_append(&cand, argv0);
+ if (file_exists(cand.data)) { bin = strdup(cand.data); break; }
+ p = colon ? colon + 1 : NULL;
+ }
+ sb_free(&cand);
+ }
+ }
+ if (bin) {
+ /* strip the binary name, keep the dir */
+ char *slash = strrchr(bin, '/');
+ if (slash) *slash = '\0';
+ /* source tree: /share/layouts + /share/bb/lib/bb.sh */
+ strbuf cand; sb_init(&cand);
+ sb_printf(&cand, "%s/share/layouts", bin);
+ if (file_exists(cand.data)) {
+ sb_free(&cand); sb_init(&cand);
+ sb_printf(&cand, "%s/share", bin);
+ sb_append(&g_share, cand.data);
+ sb_free(&cand); sb_init(&cand);
+ sb_printf(&cand, "%s/share/bb/lib/bb.sh", bin);
+ sb_append(&g_lib, cand.data);
+ sb_free(&cand);
+ free(bin);
+ return;
+ }
+ /* installed: /share/bb/layouts + /share/bb/lib/bb.sh */
+ sb_free(&cand); sb_init(&cand);
+ sb_printf(&cand, "%s/share/bb/layouts", bin);
+ if (file_exists(cand.data)) {
+ sb_free(&cand); sb_init(&cand);
+ sb_printf(&cand, "%s/share/bb", bin);
+ sb_append(&g_share, cand.data);
+ sb_free(&cand); sb_init(&cand);
+ sb_printf(&cand, "%s/share/bb/lib/bb.sh", bin);
+ sb_append(&g_lib, cand.data);
+ sb_free(&cand);
+ free(bin);
+ return;
+ }
+ sb_free(&cand);
+ free(bin);
+ }
+ /* cwd fallback: source tree */
+ if (file_exists("share/layouts")) {
+ sb_append(&g_share, "share");
+ sb_append(&g_lib, "share/bb/lib/bb.sh");
+ } else {
+ sb_append(&g_share, "share/bb");
+ sb_append(&g_lib, "share/bb/lib/bb.sh");
+ }
+}
+
+static void mkdirs(const char *path) {
+ /* create parent dirs of a file path (or the dir itself if it ends in /) */
+ strbuf tmp; sb_init(&tmp);
+ sb_append(&tmp, path);
+ /* if path ends with a filename, stop before the last component */
+ if (tmp.len > 0 && tmp.data[tmp.len - 1] != '/') {
+ char *slash = strrchr(tmp.data, '/');
+ if (slash) *slash = '\0';
+ }
+ for (char *p = tmp.data + 1; *p; p++) {
+ if (*p == '/') {
+ *p = '\0';
+ mkdir(tmp.data, 0755);
+ *p = '/';
+ }
+ }
+ if (tmp.data[0]) mkdir(tmp.data, 0755);
+ sb_free(&tmp);
+}
+
+/* Build the environment for a layout script. Returns NULL-terminated array.
+ * fm is the page/post frontmatter (may be NULL); its keys become FM_. */
+static char **build_env(const config *cfg, const config *theme, const config *fm,
+ const char *content_file, const char *title, const char *theme_name,
+ const char *nav, const char *posts_file, const char *pages_file,
+ int depth, const char *lang) {
+ /* count: base vars + config keys + theme keys + fm keys + nav */
+ size_t n = 18 + cfg->count + (theme ? theme->count : 0) + (fm ? fm->count : 0);
+ char **env = calloc(n + 1, sizeof(char *));
+ if (!env) return NULL;
+ size_t i = 0;
+ strbuf b; sb_init(&b);
+ sb_printf(&b, "SITE_TITLE=%s", config_get(cfg, "title") ? config_get(cfg, "title") : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "SITE_DESC=%s", config_get(cfg, "description") ? config_get(cfg, "description") : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ /* LANG: "" for the default language, else the language code (de, pt, ...).
+ * Layouts use it for the language switcher and . */
+ sb_printf(&b, "LANG=%s", lang ? lang : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ /* BB_LANGS: space-separated list of all available language codes
+ * (excluding the default ""). Layouts use it to render a switcher.
+ * BB_LANG_DEFAULT: the default language code via pages. symlink,
+ * empty when the default has no marker (legacy: LANG="" root). */
+ sb_printf(&b, "BB_LANGS=%s", g_langs.data ? g_langs.data : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "BB_LANG_DEFAULT=%s", g_lang_default ? g_lang_default : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "CONTENT_FILE=%s", content_file);
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "PAGE_TITLE=%s", title ? title : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "THEME=%s", theme_name);
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "NAV=%s", nav ? nav : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "BB_POSTS_FILE=%s", posts_file ? posts_file : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "BB_PAGES_FILE=%s", pages_file ? pages_file : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ sb_printf(&b, "BB_LIB=%s", g_lib.data ? g_lib.data : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ /* page depth + relative prefix for links ("../" * depth) */
+ sb_printf(&b, "BB_DEPTH=%d", depth);
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ strbuf prefix; sb_init(&prefix);
+ for (int d = 0; d < depth; d++) sb_append(&prefix, "../");
+ sb_printf(&b, "BB_PREFIX=%s", prefix.data ? prefix.data : "");
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_free(&prefix);
+ /* FONT_CSS: substitute the @PREFIX@ placeholder with the relative prefix */
+ strbuf font_css; sb_init(&font_css);
+ if (g_font_css.data && g_font_css.data[0]) {
+ const char *ph = "@PREFIX@";
+ const char *p = g_font_css.data;
+ while ((p = strstr(p, ph))) {
+ sb_append_n(&font_css, g_font_css.data, (size_t)(p - g_font_css.data));
+ sb_append(&font_css, prefix.data);
+ p += strlen(ph);
+ }
+ sb_append(&font_css, p);
+ }
+ sb_init(&b);
+ sb_printf(&b, "FONT_CSS=%s", font_css.data);
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_free(&font_css); sb_init(&b);
+ /* HTML_LANG_ATTR: ' lang="de"' for language pages, "" for default.
+ * With a default-language marker (pages.en symlink), root pages get
+ * that language's code. */
+ if (lang && lang[0]) {
+ sb_printf(&b, "HTML_LANG_ATTR= lang=\"%s\"", lang);
+ } else if (g_lang_default && g_lang_default[0]) {
+ sb_printf(&b, "HTML_LANG_ATTR= lang=\"%s\"", g_lang_default);
+ } else {
+ sb_printf(&b, "HTML_LANG_ATTR=");
+ }
+ env[i++] = strdup(b.data);
+ sb_free(&b); sb_init(&b);
+ /* pass through PATH */
+ const char *path = getenv("PATH");
+ sb_printf(&b, "PATH=%s", path ? path : "/bin:/usr/bin");
+ env[i++] = strdup(b.data);
+ sb_free(&b);
+ /* config keys as env vars (uppercased) */
+ for (size_t k = 0; k < cfg->count; k++) {
+ strbuf key; sb_init(&key);
+ for (const char *c = cfg->keys[k]; *c; c++) {
+ char ch = *c;
+ sb_append_char(&key, (ch >= 'a' && ch <= 'z') ? (char)(ch - 'a' + 'A') : ch);
+ }
+ /* THEME is exported once, from the resolved theme name above. A
+ * `theme` key in site.conf must not shadow it with a second value. */
+ if (strcmp(key.data, "THEME") == 0) { sb_free(&key); continue; }
+ sb_init(&b);
+ sb_printf(&b, "%s=%s", key.data, cfg->vals[k]);
+ env[i++] = strdup(b.data);
+ sb_free(&b);
+ sb_free(&key);
+ }
+ /* theme keys as env vars (uppercased) */
+ if (theme) {
+ for (size_t k = 0; k < theme->count; k++) {
+ strbuf key; sb_init(&key);
+ for (const char *c = theme->keys[k]; *c; c++) {
+ char ch = *c;
+ sb_append_char(&key, (ch >= 'a' && ch <= 'z') ? (char)(ch - 'a' + 'A') : ch);
+ }
+ sb_init(&b);
+ sb_printf(&b, "%s=%s", key.data, theme->vals[k]);
+ env[i++] = strdup(b.data);
+ sb_free(&b);
+ sb_free(&key);
+ }
+ }
+ /* frontmatter keys as FM_ env vars (uppercased) */
+ if (fm) {
+ for (size_t k = 0; k < fm->count; k++) {
+ strbuf key; sb_init(&key);
+ sb_append(&key, "FM_");
+ for (const char *c = fm->keys[k]; *c; c++) {
+ char ch = *c;
+ sb_append_char(&key, (ch >= 'a' && ch <= 'z') ? (char)(ch - 'a' + 'A') : ch);
+ }
+ sb_init(&b);
+ sb_printf(&b, "%s=%s", key.data, fm->vals[k]);
+ env[i++] = strdup(b.data);
+ sb_free(&b);
+ sb_free(&key);
+ }
+ }
+ env[i] = NULL;
+ return env;
+}
+
+static void free_env(char **env) {
+ if (!env) return;
+ for (size_t i = 0; env[i]; i++) free(env[i]);
+ free(env);
+}
+
+/* Render one markdown file through the layout into dist/.
+ * Memory-efficient: markdown is streamed line-by-line into the content
+ * file, and the layout output is streamed straight into the dist file.
+ * No page is ever fully buffered in RAM. */
+static void render_page(const config *cfg, const config *theme, const char *src, const char *dst,
+ const char *layout, const char *title, const char *nav,
+ const char *posts_file, const char *pages_file, int depth, const char *lang) {
+ /* open source markdown */
+ FILE *sf = fopen(src, "rb");
+ if (!sf) { fprintf(stderr, "bb: cannot read %s\n", src); return; }
+
+ /* content temp file */
+ strbuf content_file; sb_init(&content_file);
+ sb_printf(&content_file, "%s/content-%d.html", g_tmpdir.data, (int)getpid());
+ FILE *cf = fopen(content_file.data, "w");
+ if (!cf) { fclose(sf); sb_free(&content_file); return; }
+
+ /* stream markdown -> html into content file (parser reads from sf) */
+ strbuf md_prefix; sb_init(&md_prefix);
+ for (int d = 0; d < depth; d++) sb_append(&md_prefix, "../");
+ markdown_to_html(cf, sf, md_prefix.data);
+ sb_free(&md_prefix);
+ fclose(sf);
+ fclose(cf);
+
+ /* run layout script, streaming output straight into dist */
+ config fm; config_init(&fm);
+ frontmatter_load(src, &fm);
+ /* prefer the page's frontmatter title; fall back to the route name */
+ const char *fm_title = config_get(&fm, "title");
+ char **env = build_env(cfg, theme, &fm, content_file.data,
+ (fm_title && fm_title[0]) ? fm_title : title,
+ g_theme, nav, posts_file, pages_file, depth, lang);
+ config_free(&fm);
+ mkdirs(dst);
+ FILE *of = fopen(dst, "w");
+ if (of) {
+ if (template_run(layout, env, of) != 0) {
+ fprintf(stderr, "bb: layout failed: %s\n", layout);
+ }
+ fclose(of);
+ }
+
+ free_env(env);
+ unlink(content_file.data);
+ sb_free(&content_file);
+}
+
+static void buildpages(const config *cfg, const config *theme, const char *pages_dir, const char *dist_dir, const char *layout, const char *nav, const char *posts_file, const char *pages_file, const char *lang) {
+ DIR *d = opendir(pages_dir);
+ if (!d) return;
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf src, dst, route;
+ sb_init(&src); sb_init(&dst); sb_init(&route);
+ sb_printf(&src, "%s/%s", pages_dir, e->d_name);
+ /* strip .md, use as route */
+ sb_append_n(&route, e->d_name, len - 3);
+ /* index.md -> dist/index.html (depth 0), others -> dist//index.html (depth 1).
+ * For a non-default language, pages live under dist//... and the
+ * depth grows by one (the language prefix is a path segment). */
+ int depth;
+ if (strcmp(route.data, "index") == 0) {
+ if (lang && lang[0]) {
+ sb_printf(&dst, "%s/%s/index.html", dist_dir, lang);
+ depth = 1;
+ } else {
+ sb_printf(&dst, "%s/index.html", dist_dir);
+ depth = 0;
+ }
+ } else {
+ if (lang && lang[0]) {
+ sb_printf(&dst, "%s/%s/%s/index.html", dist_dir, lang, route.data);
+ depth = 2;
+ } else {
+ sb_printf(&dst, "%s/%s/index.html", dist_dir, route.data);
+ depth = 1;
+ }
+ }
+ render_page(cfg, theme, src.data, dst.data, layout, route.data, nav, posts_file, pages_file, depth, lang);
+ sb_free(&src); sb_free(&dst); sb_free(&route);
+ }
+ closedir(d);
+}
+
+/* Build a nav string from the page routes: "Home|/|About|/about/|..."
+ * index.md is always first, labeled "Home", pointing to "/".
+ * Nav entries need frontmatter `menu: true` (opt-in, like Node bb);
+ * `menuLabel` overrides the label, `menuOrder` sorts (lower first). */
+static int nav_entry_cmp(const void *a, const void *b);
+
+typedef struct {
+ char *label;
+ char *url;
+ long order;
+} nav_entry;
+
+static int nav_entry_cmp(const void *a, const void *b) {
+ const nav_entry *x = a, *y = b;
+ if (x->order != y->order) return (x->order < y->order) ? -1 : 1;
+ return strcmp(x->label, y->label);
+}
+
+static void build_nav(strbuf *nav, const char *pages_dir, const char *lang) {
+ DIR *d = opendir(pages_dir);
+ if (!d) return;
+ struct dirent *e;
+ nav_entry *entries = NULL;
+ size_t count = 0, cap = 0;
+ /* collect pages with menu: true */
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf route; sb_init(&route);
+ sb_append_n(&route, e->d_name, len - 3);
+ if (strcmp(route.data, "index") != 0) {
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "%s/%s", pages_dir, e->d_name);
+ char *menu = frontmatter_value(path.data, "menu");
+ if (menu && strcmp(menu, "true") == 0) {
+ if (count == cap) {
+ cap = cap ? cap * 2 : 8;
+ entries = realloc(entries, cap * sizeof(nav_entry));
+ }
+ char *label = frontmatter_value(path.data, "menuLabel");
+ if (!label || !label[0]) {
+ free(label);
+ label = strdup(route.data);
+ if (label[0] >= 'a' && label[0] <= 'z')
+ label[0] = (char)(label[0] - 'a' + 'A');
+ }
+ char *order = frontmatter_value(path.data, "menuOrder");
+ strbuf url; sb_init(&url);
+ if (lang && lang[0]) sb_printf(&url, "/%s/%s/", lang, route.data);
+ else sb_printf(&url, "/%s/", route.data);
+ entries[count].label = label; /* malloc'ed, freed below */
+ entries[count].url = url.data; /* strbuf data, freed below */
+ entries[count].order = order ? atol(order) : 0;
+ count++;
+ free(order);
+ } else {
+ if (menu) free(menu);
+ }
+ sb_free(&path);
+ }
+ sb_free(&route);
+ }
+ closedir(d);
+ qsort(entries, count, sizeof(nav_entry), nav_entry_cmp);
+ if (lang && lang[0]) sb_printf(nav, "Home|/%s/", lang);
+ else sb_append(nav, "Home|/");
+ if (lang && lang[0]) {
+ /* language blog if posts./ exists, else the default blog */
+ char pd[128];
+ snprintf(pd, sizeof pd, "posts.%s", lang);
+ if (file_exists(pd)) sb_printf(nav, "|Blog|/%s/blog/", lang);
+ else if (file_exists("posts")) sb_append(nav, "|Blog|/blog/");
+ } else if (file_exists("posts")) {
+ sb_append(nav, "|Blog|/blog/");
+ }
+ for (size_t i = 0; i < count; i++) {
+ if (nav->len > 0) sb_append(nav, "|");
+ sb_printf(nav, "%s|%s", entries[i].label, entries[i].url);
+ free(entries[i].label);
+ free(entries[i].url);
+ }
+ free(entries);
+}
+
+/* Collect posts from posts/ into an array. Returns count. */
+static Post **collectposts(const char *posts_dir, size_t *count) {
+ *count = 0;
+ DIR *d = opendir(posts_dir);
+ if (!d) return NULL;
+ size_t cap = 8;
+ Post **posts = malloc(cap * sizeof(Post *));
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf src; sb_init(&src);
+ sb_printf(&src, "%s/%s", posts_dir, e->d_name);
+ Post *p = post_parse(src.data);
+ sb_free(&src);
+ if (!p) continue;
+ if (*count == cap) {
+ cap *= 2;
+ posts = realloc(posts, cap * sizeof(Post *));
+ }
+ posts[(*count)++] = p;
+ }
+ closedir(d);
+ return posts;
+}
+
+/* Render the blog index (list of posts) and archive. */
+static void render_blog(const config *cfg, const config *theme, Post **posts, size_t n,
+ const char *dist_dir, const char *layout, const char *nav,
+ const char *posts_file, const char *pages_file, const char *lang) {
+ if (n == 0) return;
+ /* build a content file with the post list, streamed */
+ strbuf content_file; sb_init(&content_file);
+ sb_printf(&content_file, "%s/blog-%d.html", g_tmpdir.data, (int)getpid());
+ FILE *cf = fopen(content_file.data, "w");
+ if (!cf) { sb_free(&content_file); return; }
+ fputs("Blog \n\n", cf);
+ for (size_t i = 0; i < n; i++) {
+ fprintf(cf, "%s (%s) \n",
+ posts[i]->slug, posts[i]->title ? posts[i]->title : posts[i]->slug,
+ posts[i]->date ? posts[i]->date : "");
+ }
+ fputs(" \n", cf);
+ fclose(cf);
+
+ /* depth: blog index sits one level below dist root; two with a language
+ * prefix (dist//blog/). */
+ int depth = (lang && lang[0]) ? 2 : 1;
+ char **env = build_env(cfg, theme, NULL, content_file.data, "Blog", g_theme, nav, posts_file, pages_file, depth, lang);
+ strbuf dst; sb_init(&dst);
+ if (lang && lang[0]) {
+ sb_printf(&dst, "%s/%s/blog/index.html", dist_dir, lang);
+ } else {
+ sb_printf(&dst, "%s/blog/index.html", dist_dir);
+ }
+ mkdirs(dst.data);
+ FILE *of = fopen(dst.data, "w");
+ if (of) {
+ if (template_run(layout, env, of) != 0) {
+ fprintf(stderr, "bb: blog layout failed\n");
+ }
+ fclose(of);
+ }
+ sb_free(&dst);
+
+ free_env(env);
+ unlink(content_file.data);
+ sb_free(&content_file);
+}
+
+/* Render each post to dist/blog//index.html */
+static void renderposts(const config *cfg, const config *theme, Post **posts, size_t n,
+ const char *dist_dir, const char *layout, const char *nav,
+ const char *posts_file, const char *pages_file, const char *lang) {
+ for (size_t i = 0; i < n; i++) {
+ /* write post markdown to a temp file, then stream-parse it */
+ strbuf md_file, content_file, dst;
+ sb_init(&md_file); sb_init(&content_file); sb_init(&dst);
+ sb_printf(&md_file, "%s/post-md-%d.md", g_tmpdir.data, (int)getpid());
+ FILE *mf = fopen(md_file.data, "w");
+ if (mf) {
+ fputs(posts[i]->content ? posts[i]->content : "", mf);
+ fclose(mf);
+ }
+ sb_printf(&content_file, "%s/post-%d.html", g_tmpdir.data, (int)getpid());
+ FILE *cf = fopen(content_file.data, "w");
+ FILE *sf = fopen(md_file.data, "rb");
+ if (cf && sf) {
+ markdown_to_html(cf, sf, "../../");
+ }
+ if (sf) fclose(sf);
+ if (cf) fclose(cf);
+ unlink(md_file.data);
+
+ char **env = build_env(cfg, theme, &posts[i]->fm, content_file.data, posts[i]->title, g_theme, nav, posts_file, pages_file, 2, lang);
+ if (lang && lang[0]) {
+ sb_printf(&dst, "%s/%s/blog/%s/index.html", dist_dir, lang, posts[i]->slug);
+ } else {
+ sb_printf(&dst, "%s/blog/%s/index.html", dist_dir, posts[i]->slug);
+ }
+ mkdirs(dst.data);
+ FILE *of = fopen(dst.data, "w");
+ if (of) {
+ if (template_run(layout, env, of) != 0) {
+ fprintf(stderr, "bb: post layout failed: %s\n", posts[i]->slug);
+ }
+ fclose(of);
+ }
+
+ free_env(env);
+ unlink(content_file.data);
+ sb_free(&md_file); sb_free(&content_file); sb_free(&dst);
+ }
+}
+
+/* Render the RSS feed to dist/rss.xml, streamed straight to the file. */
+static void render_rss(const config *cfg, Post **posts, size_t n, const char *dist_dir) {
+ if (n == 0) return;
+ const char *title = config_get(cfg, "title") ? config_get(cfg, "title") : "BB Site";
+ const char *desc = config_get(cfg, "description") ? config_get(cfg, "description") : "";
+ const char *base = config_get(cfg, "base_url") ? config_get(cfg, "base_url") : "";
+
+ strbuf dst; sb_init(&dst);
+ sb_printf(&dst, "%s/rss.xml", dist_dir);
+ FILE *of = fopen(dst.data, "w");
+ sb_free(&dst);
+ if (!of) return;
+ fprintf(of, "\n");
+ fprintf(of, "\n\n");
+ fprintf(of, "%s \n", title);
+ fprintf(of, "%s \n", desc);
+ fprintf(of, " %s/\n", base);
+ for (size_t i = 0; i < n; i++) {
+ fprintf(of, "- \n");
+ fprintf(of, "
%s \n", posts[i]->title ? posts[i]->title : posts[i]->slug);
+ fprintf(of, " %s/blog/%s/\n", base, posts[i]->slug);
+ if (posts[i]->date) fprintf(of, "%s \n", posts[i]->date);
+ if (posts[i]->excerpt) fprintf(of, "%s \n", posts[i]->excerpt);
+ fprintf(of, " \n");
+ }
+ fprintf(of, " \n \n");
+ fclose(of);
+}
+
+/* Render sitemap.xml to dist/sitemap.xml, streamed. Lists all pages and
+ * posts under base_url. */
+static void render_sitemap(const config *cfg, Post **posts, size_t n, const char *dist_dir) {
+ const char *base = config_get(cfg, "base_url") ? config_get(cfg, "base_url") : "";
+ if (!base[0]) return; /* no base_url, no sitemap */
+
+ strbuf dst; sb_init(&dst);
+ sb_printf(&dst, "%s/sitemap.xml", dist_dir);
+ FILE *of = fopen(dst.data, "w");
+ sb_free(&dst);
+ if (!of) return;
+ fprintf(of, "\n");
+ fprintf(of, "\n");
+ /* home */
+ fprintf(of, " %s/ \n", base);
+ /* pages */
+ if (file_exists("pages")) {
+ DIR *d = opendir("pages");
+ if (d) {
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf route; sb_init(&route);
+ sb_append_n(&route, e->d_name, len - 3);
+ if (strcmp(route.data, "index") != 0) {
+ fprintf(of, " %s/%s/ \n", base, route.data);
+ }
+ sb_free(&route);
+ }
+ closedir(d);
+ }
+ }
+ /* blog index + posts */
+ if (n > 0) {
+ fprintf(of, " %s/blog/ \n", base);
+ for (size_t i = 0; i < n; i++) {
+ fprintf(of, " %s/blog/%s/ \n", base, posts[i]->slug);
+ }
+ }
+ fprintf(of, " \n");
+ fclose(of);
+}
+
+/* Copy a file from src to dst (mkdir parents first). Returns 0 on success. */
+static int copy_file(const char *src, const char *dst) {
+ FILE *fs = fopen(src, "rb");
+ if (!fs) return -1;
+ mkdirs(dst);
+ FILE *fd = fopen(dst, "wb");
+ if (!fd) { fclose(fs); return -1; }
+ char fb[4096];
+ size_t r;
+ while ((r = fread(fb, 1, sizeof(fb), fs)) > 0) fwrite(fb, 1, r, fd);
+ fclose(fs);
+ fclose(fd);
+ return 0;
+}
+
+/* Recursively copy a directory tree from src to dst (verbatim). */
+static void copy_tree(const char *src, const char *dst) {
+ DIR *d = opendir(src);
+ if (!d) return;
+ mkdirs(dst);
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ strbuf s, t;
+ sb_init(&s); sb_init(&t);
+ sb_printf(&s, "%s/%s", src, e->d_name);
+ sb_printf(&t, "%s/%s", dst, e->d_name);
+ struct stat st;
+ if (stat(s.data, &st) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ copy_tree(s.data, t.data);
+ } else {
+ copy_file(s.data, t.data);
+ }
+ }
+ sb_free(&s); sb_free(&t);
+ }
+ closedir(d);
+}
+
+/* Recursively delete a directory tree (used to wipe dist/ before a fresh
+ * build, so stale files never linger). */
+static void rm_tree(const char *path) {
+ DIR *d = opendir(path);
+ if (!d) return;
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ strbuf p;
+ sb_init(&p);
+ sb_printf(&p, "%s/%s", path, e->d_name);
+ struct stat st;
+ if (stat(p.data, &st) == 0) {
+ if (S_ISDIR(st.st_mode)) rm_tree(p.data);
+ else remove(p.data);
+ }
+ sb_free(&p);
+ }
+ closedir(d);
+ rmdir(path);
+}
+
+/* Collect all robots: frontmatter lines from .md files in a dir.
+ * Appends each value (one line per file) to out. */
+static void collect_robots_dir(const char *dir, strbuf *out) {
+ DIR *d = opendir(dir);
+ if (!d) return;
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "%s/%s", dir, e->d_name);
+ char *robots = frontmatter_value(path.data, "robots");
+ if (robots) {
+ sb_append(out, robots);
+ sb_append_char(out, '\n');
+ free(robots);
+ }
+ sb_free(&path);
+ }
+ closedir(d);
+}
+
+/* Render robots.txt to dist/robots.txt. Priority:
+ * 1. project's own robots.txt — copied verbatim
+ * 2. robots: frontmatter lines from pages/ and posts/ .md files — aggregated
+ * 3. good default: allow all + Sitemap line when base_url set */
+static void render_robots(const config *cfg, const char *dist_dir) {
+ if (file_exists("robots.txt")) {
+ copy_file("robots.txt", "dist/robots.txt");
+ return;
+ }
+ strbuf lines; sb_init(&lines);
+ if (file_exists("pages")) collect_robots_dir("pages", &lines);
+ if (file_exists("posts")) collect_robots_dir("posts", &lines);
+
+ strbuf dst; sb_init(&dst);
+ sb_printf(&dst, "%s/robots.txt", dist_dir);
+ FILE *of = fopen(dst.data, "w");
+ sb_free(&dst);
+ if (!of) { sb_free(&lines); return; }
+ if (lines.len > 0) {
+ fputs(lines.data, of);
+ } else {
+ const char *base = config_get(cfg, "base_url") ? config_get(cfg, "base_url") : "";
+ fprintf(of, "User-agent: *\n");
+ fprintf(of, "Allow: /\n");
+ if (base[0]) fprintf(of, "\nSitemap: %s/sitemap.xml\n", base);
+ }
+ fclose(of);
+ sb_free(&lines);
+}
+
+/* Write a file with given content (mkdir parents first). */
+static void write_file(const char *path, const char *content) {
+ mkdirs(path);
+ FILE *f = fopen(path, "w");
+ if (!f) { fprintf(stderr, "bb: cannot write %s\n", path); return; }
+ fputs(content, f);
+ fclose(f);
+}
+
+/* bb init [dir] — scaffold a new project. */
+static int cmd_init(const char *dir) {
+ if (!dir || !dir[0]) dir = ".";
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "%s/site.conf", dir);
+ if (file_exists(path.data)) {
+ fprintf(stderr, "bb: %s already exists — refusing to overwrite\n", path.data);
+ sb_free(&path);
+ return 1;
+ }
+ mkdirs(path.data); /* creates dir */
+
+ write_file(path.data,
+ "# bb site configuration\n"
+ "title = My BB Site\n"
+ "description = A tiny static site built in pure C\n"
+ "theme = oli7\n");
+ sb_free(&path); sb_init(&path);
+ sb_printf(&path, "%s/pages/index.md", dir);
+ write_file(path.data,
+ "# Hello BB\n\n"
+ "This is your first page. Edit `pages/index.md` and run `make`.\n\n"
+ "## Markdown works\n\n"
+ "- **bold** and *italic*\n"
+ "- `inline code`\n"
+ "- [links](https://example.com)\n\n"
+ "```sh\n"
+ "make THEME=oli7\n"
+ "```\n");
+ sb_free(&path); sb_init(&path);
+ sb_printf(&path, "%s/Makefile", dir);
+ write_file(path.data,
+ "# bb project Makefile\n"
+ "THEME ?= oli7\n"
+ "BB ?= bb\n"
+ "all: build\n"
+ "build:\n"
+ "\t$(BB) build --theme $(THEME)\n"
+ "clean:\n"
+ "\trm -rf dist\n"
+ ".PHONY: all build clean\n");
+ sb_free(&path);
+ printf("bb: initialized project in %s\n", dir);
+ printf(" next: cd %s && make THEME=oli7\n", dir);
+ return 0;
+}
+
+/* Open a file in $EDITOR if set. Returns 0 if opened, 1 if no editor.
+ * The path is passed as a positional parameter, never spliced into the
+ * command string, so spaces/metacharacters in it cannot be interpreted;
+ * $EDITOR may still carry arguments (e.g. "vim -f"). */
+static int open_editor(const char *path) {
+ const char *editor = getenv("EDITOR");
+ if (!editor || !editor[0]) return 1;
+ pid_t pid = fork();
+ if (pid < 0) return 1;
+ if (pid == 0) {
+ execl("/bin/sh", "sh", "-c", "exec $EDITOR \"$1\"", "sh", path, (char *)NULL);
+ _exit(127);
+ }
+ int status;
+ if (waitpid(pid, &status, 0) < 0) return 1;
+ return (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : 1;
+}
+
+/* Build a slug from a title: lowercase, non-alnum -> single '-'. */
+static void make_slug(strbuf *slug, const char *title) {
+ for (const char *p = title; *p; p++) {
+ char c = *p;
+ if (c >= 'A' && c <= 'Z') c = (char)(c - 'A' + 'a');
+ if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
+ sb_append_char(slug, c);
+ } else if (c == ' ' || c == '-' || c == '_') {
+ if (slug->len > 0 && slug->data[slug->len - 1] != '-') sb_append_char(slug, '-');
+ }
+ }
+ while (slug->len > 0 && slug->data[slug->len - 1] == '-') slug->len--;
+ if (slug->len > 0) slug->data[slug->len] = '\0';
+}
+
+/* bb new post "Title" — scaffold a new post in posts/. */
+static int cmd_new_post(const char *title) {
+ if (!title || !title[0]) {
+ fprintf(stderr, "bb: usage: bb new post \"Post Title\"\n");
+ return 1;
+ }
+ if (!file_exists("posts")) mkdir("posts", 0755);
+
+ /* date = today (UTC) */
+ time_t now = time(NULL);
+ struct tm *tm = gmtime(&now);
+ char date[16];
+ strftime(date, sizeof(date), "%Y-%m-%d", tm);
+
+ strbuf slug; sb_init(&slug);
+ make_slug(&slug, title);
+
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "posts/%s-%s.md", date, slug.data);
+ if (file_exists(path.data)) {
+ fprintf(stderr, "bb: %s already exists\n", path.data);
+ sb_free(&slug); sb_free(&path);
+ return 1;
+ }
+ strbuf content; sb_init(&content);
+ sb_printf(&content,
+ "---\n"
+ "title: \"%s\"\n"
+ "excerpt: \"\"\n"
+ "---\n"
+ "\n"
+ "Write your post here.\n", title);
+ write_file(path.data, content.data);
+ printf("bb: created %s\n", path.data);
+ if (open_editor(path.data) != 0) {
+ printf(" (set $EDITOR to open it automatically)\n");
+ }
+ sb_free(&slug); sb_free(&path); sb_free(&content);
+ return 0;
+}
+
+/* bb new page "Title" — scaffold a new page in pages/. */
+static int cmd_new_page(const char *title) {
+ if (!title || !title[0]) {
+ fprintf(stderr, "bb: usage: bb new page \"Page Title\"\n");
+ return 1;
+ }
+ if (!file_exists("pages")) mkdir("pages", 0755);
+
+ strbuf slug; sb_init(&slug);
+ make_slug(&slug, title);
+
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "pages/%s.md", slug.data);
+ if (file_exists(path.data)) {
+ fprintf(stderr, "bb: %s already exists\n", path.data);
+ sb_free(&slug); sb_free(&path);
+ return 1;
+ }
+ strbuf content; sb_init(&content);
+ sb_printf(&content,
+ "---\n"
+ "title: \"%s\"\n"
+ "excerpt: \"\"\n"
+ "---\n"
+ "\n"
+ "Write your page here.\n", title);
+ write_file(path.data, content.data);
+ printf("bb: created %s\n", path.data);
+ if (open_editor(path.data) != 0) {
+ printf(" (set $EDITOR to open it automatically)\n");
+ }
+ sb_free(&slug); sb_free(&path); sb_free(&content);
+ return 0;
+}
+
+static int name_cmp(const void *a, const void *b) {
+ return strcmp(*(char *const *)a, *(char *const *)b);
+}
+
+/* bb theme check [--strict] [name ...]: report which theme palettes are not
+ * readable as written and what bb adjusts at build time. */
+static int cmd_theme(int argc, char **argv) {
+ if (argc < 3 || strcmp(argv[2], "check") != 0) {
+ fprintf(stderr, "bb: usage: bb theme check [--strict] [name ...]\n");
+ return 1;
+ }
+ int strict = 0, first = 3;
+ if (argc > 3 && strcmp(argv[3], "--strict") == 0) { strict = 1; first = 4; }
+ find_share(argv[0]);
+
+ char **names = NULL;
+ size_t n = 0, cap = 0;
+ if (first < argc) {
+ for (int i = first; i < argc; i++) {
+ if (n == cap) { cap = cap ? cap * 2 : 16; names = realloc(names, cap * sizeof *names); }
+ names[n++] = strdup(argv[i]);
+ }
+ } else {
+ strbuf dir; sb_init(&dir);
+ sb_printf(&dir, "%s/themes", g_share.data);
+ DIR *d = opendir(dir.data);
+ if (!d) { fprintf(stderr, "bb: cannot open %s\n", dir.data); sb_free(&dir); return 1; }
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ size_t l = strlen(e->d_name);
+ if (l < 6 || strcmp(e->d_name + l - 5, ".conf") != 0) continue;
+ if (n == cap) { cap = cap ? cap * 2 : 16; names = realloc(names, cap * sizeof *names); }
+ names[n] = strdup(e->d_name);
+ names[n][l - 5] = '\0';
+ n++;
+ }
+ closedir(d);
+ sb_free(&dir);
+ qsort(names, n, sizeof *names, name_cmp);
+ }
+
+ size_t dirty = 0;
+ for (size_t i = 0; i < n; i++) {
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "%s/themes/%s.conf", g_share.data, names[i]);
+ if (theme_check_file(path.data, names[i], stdout) > 0) dirty++;
+ sb_free(&path);
+ free(names[i]);
+ }
+ free(names);
+ printf("%lu theme%s checked, %lu needed contrast fixes (applied automatically at build time)\n",
+ (unsigned long)n, n == 1 ? "" : "s", (unsigned long)dirty);
+ return (strict && dirty) ? 1 : 0;
+}
+
+int main(int argc, char **argv) {
+ /* parse args */
+ const char *cmd = argc > 1 ? argv[1] : NULL;
+ if (cmd && strcmp(cmd, "init") == 0) {
+ return cmd_init(argc > 2 ? argv[2] : NULL);
+ }
+ if (cmd && strcmp(cmd, "new") == 0 && argc > 2 && strcmp(argv[2], "post") == 0) {
+ return cmd_new_post(argc > 3 ? argv[3] : NULL);
+ }
+ if (cmd && strcmp(cmd, "new") == 0 && argc > 2 && strcmp(argv[2], "page") == 0) {
+ return cmd_new_page(argc > 3 ? argv[3] : NULL);
+ }
+ if (cmd && strcmp(cmd, "theme") == 0) {
+ return cmd_theme(argc, argv);
+ }
+ if (cmd && strcmp(cmd, "serve") == 0) {
+ return cmd_serve(argc, argv);
+ }
+ if (cmd && (strcmp(cmd, "--help") == 0 || strcmp(cmd, "-h") == 0)) {
+ printf("bb — C99 static site generator\n"
+ "Usage:\n"
+ " bb init [dir] Scaffold a new project\n"
+ " bb new post \"Title\" Create a new blog post\n"
+ " bb new page \"Title\" Create a new page\n"
+ " bb build [--theme N] Build current project into dist/\n"
+ " bb theme check [--strict] [name ...]\n"
+ " Report theme contrast problems\n"
+ " bb serve [--port N] [--bind ADDR] [--dir DIR]\n"
+ " Preview dist/ over HTTP (default 127.0.0.1:8000)\n");
+ return 0;
+ }
+ if (cmd && strcmp(cmd, "build") != 0) {
+ fprintf(stderr, "bb: unknown command '%s'\n", cmd);
+ return 1;
+ }
+
+ /* build */
+ int theme_from_cli = 0;
+ for (int i = 2; i < argc; i++) {
+ if (strcmp(argv[i], "--theme") == 0 && i + 1 < argc) {
+ g_theme = argv[++i];
+ theme_from_cli = 1;
+ }
+ }
+
+ if (!file_exists("site.conf")) die("no site.conf in current directory");
+ /* wipe dist/ so a build is always fresh — stale files never linger.
+ * overlay/ is copied back in verbatim at the end. */
+ if (file_exists("dist")) rm_tree("dist");
+ mkdir("dist", 0755);
+
+ find_share(argv[0]);
+
+ /* build temp dir (not /tmp, not dist/) */
+ sb_init(&g_tmpdir);
+ sb_append(&g_tmpdir, "build");
+ mkdirs("build/");
+
+ /* i18n: scan for pages./ and posts./ directories and collect
+ * the language codes into g_langs (space-separated). The layout gets
+ * LANG ("" = default) + BB_LANGS in its env. */
+ sb_init(&g_langs);
+ {
+ DIR *d = opendir(".");
+ if (d) {
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ const char *p = e->d_name;
+ const char *lang = NULL;
+ if (strncmp(p, "pages.", 6) == 0) lang = p + 6;
+ else if (strncmp(p, "posts.", 6) == 0) lang = p + 6;
+ if (!lang || !lang[0]) continue;
+ struct stat st;
+ /* symlink handling first: pages. -> pages/ marks the
+ * default language (registered, no separate build tree).
+ * Symlinks pointing anywhere else are ignored. */
+ struct stat lst;
+ if (lstat(p, &lst) == 0 && S_ISLNK(lst.st_mode)) {
+ if (strncmp(p, "pages.", 6) == 0) {
+ struct stat tgt;
+ if (stat("pages", &tgt) == 0 && S_ISDIR(tgt.st_mode) &&
+ stat(p, &st) == 0 && st.st_ino == tgt.st_ino &&
+ st.st_dev == tgt.st_dev) {
+ g_lang_default = strdup(lang);
+ sb_append(&g_langs, lang);
+ sb_append(&g_langs, " ");
+ }
+ }
+ continue;
+ }
+ if (stat(p, &st) != 0 || !S_ISDIR(st.st_mode)) continue;
+ sb_append(&g_langs, lang);
+ sb_append(&g_langs, " ");
+ }
+ closedir(d);
+ }
+ }
+
+ config cfg; config_init(&cfg);
+ if (config_load(&cfg, "site.conf") != 0) die("cannot read site.conf");
+
+ /* theme precedence: --theme on the command line, else `theme` in
+ * site.conf, else the built-in default. */
+ if (!theme_from_cli) {
+ const char *t = config_get(&cfg, "theme");
+ if (t && t[0]) g_theme = t;
+ }
+
+ /* load theme config */
+ config theme; config_init(&theme);
+ strbuf theme_path; sb_init(&theme_path);
+ sb_printf(&theme_path, "%s/themes/%s.conf", g_share.data, g_theme);
+ if (file_exists(theme_path.data)) {
+ config_load(&theme, theme_path.data);
+ } else {
+ fprintf(stderr, "bb: theme '%s' not found in %s/themes/, using defaults\n", g_theme, g_share.data);
+ }
+ sb_free(&theme_path);
+ theme_normalize(&theme, NULL);
+
+ /* layout path: /layouts/layout.sh */
+ strbuf layout; sb_init(&layout);
+ sb_printf(&layout, "%s/layouts/layout.sh", g_share.data);
+
+ /* optional fonts: site.conf keys
+ * font — base font for body text: monospace|sans|serif (copies
+ * share/fonts/.ttf, emits @font-face) or omitted
+ * font_h1..font_h6, font_code — per-element override; value is either a
+ * font name with a bundled ttf (share/fonts/.ttf) or
+ * a raw CSS font-family list (e.g. "Georgia, serif").
+ * Every referenced ttf lands in dist/assets/fonts/ with a @font-face.
+ * Themes carry their original font stacks as font/font.code defaults —
+ * site.conf values win over theme values. */
+ sb_init(&g_font_css);
+ {
+ strbuf css_faces, css_rules;
+ sb_init(&css_faces); sb_init(&css_rules);
+
+ /* helper-ish: resolve one font setting into @font-face + family name.
+ * returns malloc'd family string (caller frees) or NULL if unset. */
+ const char *keys[] = {"font.h1", "font.h2", "font.h3", "font.h4",
+ "font.h5", "font.h6", "font.code"};
+ /* generic CSS families (monospace/sans/serif) are never copied as ttf
+ * — they pass through as raw font-family. Anything else that has a
+ * bundled share/fonts/.ttf gets copied + @font-face; anything
+ * else is raw CSS passed through. */
+ for (int k = 0; k < 7; k++) {
+ const char *val = config_get(&cfg, keys[k]);
+ if (!val || !val[0]) val = config_get(&theme, keys[k]);
+ if (!val || !val[0]) continue;
+ int generic = strcmp(val, "monospace") == 0 ||
+ strcmp(val, "sans") == 0 ||
+ strcmp(val, "serif") == 0;
+ strbuf src; sb_init(&src);
+ sb_printf(&src, "%s/fonts/%s.ttf", g_share.data, val);
+ if (!generic && file_exists(src.data)) {
+ /* bundled font: copy + @font-face */
+ strbuf dst, base;
+ sb_init(&dst); sb_init(&base);
+ sb_printf(&dst, "dist/assets/fonts/%s.ttf", val);
+ mkdirs(dst.data);
+ FILE *fs = fopen(src.data, "rb");
+ FILE *fd = fopen(dst.data, "wb");
+ if (fs && fd) {
+ char fb[4096];
+ size_t r;
+ while ((r = fread(fb, 1, sizeof(fb), fs)) > 0) fwrite(fb, 1, r, fd);
+ }
+ if (fs) fclose(fs);
+ if (fd) fclose(fd);
+ sb_printf(&base, "bb-%s", val);
+ sb_printf(&css_faces,
+ "@font-face{font-family:'%s';src:url('@PREFIX@assets/fonts/%s.ttf') format('truetype');}",
+ base.data, val);
+ sb_printf(&css_rules, "%s { font-family: '%s', %s; }\n",
+ strcmp(keys[k], "font.code") == 0 ? "pre, code" : keys[k] + 5,
+ base.data,
+ strcmp(keys[k], "font.code") == 0 ? "monospace" : "inherit");
+ if (strcmp(keys[k], "font.code") == 0) {
+ free(g_font_code);
+ g_font_code = strdup(base.data);
+ }
+ sb_free(&dst); sb_free(&base);
+ } else {
+ /* generic or raw CSS font-family list — no magic, pass through */
+ sb_printf(&css_rules, "%s { font-family: %s; }\n",
+ strcmp(keys[k], "font.code") == 0 ? "pre, code" : keys[k] + 5, val);
+ if (strcmp(keys[k], "font.code") == 0) {
+ free(g_font_code);
+ g_font_code = strdup(val);
+ }
+ }
+ sb_free(&src);
+ }
+ /* base font: site.conf `font`, else theme original font stack */
+ const char *font = config_get(&cfg, "font");
+ if (!font || !font[0]) font = config_get(&theme, "font");
+ if (font && font[0]) {
+ strbuf src, dst, base;
+ sb_init(&src); sb_init(&dst); sb_init(&base);
+ sb_printf(&src, "%s/fonts/%s.ttf", g_share.data, font);
+ if (file_exists(src.data)) {
+ sb_printf(&dst, "dist/assets/fonts/%s.ttf", font);
+ mkdirs(dst.data);
+ FILE *fs = fopen(src.data, "rb");
+ FILE *fd = fopen(dst.data, "wb");
+ if (fs && fd) {
+ char fb[4096];
+ size_t r;
+ while ((r = fread(fb, 1, sizeof(fb), fs)) > 0) fwrite(fb, 1, r, fd);
+ }
+ if (fs) fclose(fs);
+ if (fd) fclose(fd);
+ sb_printf(&base, "bb-%s", font);
+ sb_printf(&css_faces,
+ "@font-face{font-family:'%s';src:url('@PREFIX@assets/fonts/%s.ttf') format('truetype');}",
+ base.data, font);
+ } else {
+ /* a bare word is probably meant as a bundled font; a list or
+ * quoted family is plain CSS and needs no warning */
+ if (!strpbrk(font, ", '\"")) {
+ fprintf(stderr, "bb: font '%s' not found in %s/fonts/, using OS default\n", font, g_share.data);
+ }
+ sb_printf(&base, "%s", font);
+ }
+ sb_printf(&g_font_css, "%s%s",
+ css_faces.data ? css_faces.data : "",
+ css_rules.data ? css_rules.data : "");
+ g_font_body = strdup(base.data);
+ sb_free(&src); sb_free(&dst); sb_free(&base);
+ } else {
+ sb_printf(&g_font_css, "%s%s",
+ css_faces.data ? css_faces.data : "",
+ css_rules.data ? css_rules.data : "");
+ }
+ sb_free(&css_faces); sb_free(&css_rules);
+ }
+
+ /* write dist/css/style.css (theme palette + font-face) and ensure
+ * dist/css/custom.css exists (created once, never overwritten). */
+ mkdirs("dist/css/");
+ FILE *css = fopen("dist/css/style.css", "w");
+ if (css) {
+ /* normalize the theme tokens, then render share/layouts/theme.css */
+ strbuf tmpl_path; sb_init(&tmpl_path);
+ sb_printf(&tmpl_path, "%s/layouts/theme.css", g_share.data);
+ FILE *tf = fopen(tmpl_path.data, "r");
+ if (!tf) {
+ fprintf(stderr, "bb: cannot read %s\n", tmpl_path.data);
+ fclose(css);
+ sb_free(&tmpl_path);
+ return 1;
+ }
+ strbuf tmpl; sb_init(&tmpl);
+ char tb[4096];
+ size_t tr;
+ while ((tr = fread(tb, 1, sizeof tb, tf)) > 0) sb_append_n(&tmpl, tb, tr);
+ fclose(tf);
+ sb_free(&tmpl_path);
+
+ config_set(&theme, "font.body.css", g_font_body ? g_font_body : "Georgia, serif");
+ config_set(&theme, "font.code.css", g_font_code ? g_font_code : "monospace");
+ strbuf rendered; sb_init(&rendered);
+ theme_render(&rendered, tmpl.data ? tmpl.data : "", &theme);
+
+ fprintf(css, "/* bb theme: %s */\n", g_theme);
+ if (g_font_css.data && g_font_css.data[0]) fprintf(css, "%s\n", g_font_css.data);
+ if (rendered.data) fputs(rendered.data, css);
+ fclose(css);
+ sb_free(&tmpl);
+ sb_free(&rendered);
+ }
+ if (!file_exists("dist/css/custom.css")) {
+ FILE *cc = fopen("dist/css/custom.css", "w");
+ if (cc) {
+ fprintf(cc, "/* custom.css — your own styles.\n"
+ " * This file is created once by bb and never touched again.\n"
+ " * Custom code goes here. */\n");
+ fclose(cc);
+ }
+ }
+
+ /* build nav from pages */
+ strbuf nav; sb_init(&nav);
+ if (file_exists("pages")) {
+ build_nav(&nav, "pages", NULL);
+ }
+ const char *nav_str = nav.data ? nav.data : "";
+
+ /* data files for lib/bb.sh: one post/page per line, pipe-separated */
+ strbuf posts_file, pages_file;
+ sb_init(&posts_file); sb_init(&pages_file);
+ sb_printf(&posts_file, "%s/posts-%d.txt", g_tmpdir.data, (int)getpid());
+ sb_printf(&pages_file, "%s/pages-%d.txt", g_tmpdir.data, (int)getpid());
+ FILE *pf = fopen(posts_file.data, "w");
+ FILE *pgf = fopen(pages_file.data, "w");
+ if (pf && file_exists("posts")) {
+ size_t n = 0;
+ Post **posts = collectposts("posts", &n);
+ for (size_t i = 0; i < n; i++) {
+ fprintf(pf, "%s|%s|%s|/blog/%s/\n",
+ posts[i]->slug,
+ posts[i]->title ? posts[i]->title : posts[i]->slug,
+ posts[i]->date ? posts[i]->date : "",
+ posts[i]->slug);
+ } for (size_t i = 0; i < n; i++) post_free(posts[i]);
+ free(posts);
+ }
+ if (pgf && file_exists("pages")) {
+ DIR *d = opendir("pages");
+ if (d) {
+ struct dirent *e;
+ /* index first */
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf route; sb_init(&route);
+ sb_append_n(&route, e->d_name, len - 3);
+ if (strcmp(route.data, "index") == 0) {
+ fprintf(pgf, "Home|/\n");
+ sb_free(&route);
+ break;
+ }
+ sb_free(&route);
+ }
+ rewinddir(d);
+ /* rest */
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ size_t len = strlen(e->d_name);
+ if (len < 3 || strcmp(e->d_name + len - 3, ".md") != 0) continue;
+ strbuf route, label;
+ sb_init(&route); sb_init(&label);
+ sb_append_n(&route, e->d_name, len - 3);
+ if (strcmp(route.data, "index") == 0) { sb_free(&route); sb_free(&label); continue; }
+ sb_append(&label, route.data);
+ if (label.data[0] >= 'a' && label.data[0] <= 'z') label.data[0] = (char)(label.data[0] - 'a' + 'A');
+ fprintf(pgf, "%s|/%s/\n", label.data, route.data);
+ sb_free(&route); sb_free(&label);
+ }
+ closedir(d);
+ }
+ }
+ if (pf) fclose(pf);
+ if (pgf) fclose(pgf);
+
+ if (file_exists("pages")) {
+ buildpages(&cfg, &theme, "pages", "dist", layout.data, nav_str, posts_file.data, pages_file.data, "");
+ }
+
+ /* i18n: any pages./ directory (e.g. pages.de/, pages.pt/) builds
+ * into dist// with LANG= set for the layout. A pages.
+ * SYMLINK to pages/ marks as the site's default language: it is
+ * registered for the switcher and used as the html lang attribute for
+ * the default (root) pages, but NOT built as a duplicate tree. */
+ {
+ DIR *d = opendir(".");
+ if (d) {
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ const char *p = e->d_name;
+ if (strncmp(p, "pages.", 6) != 0) continue;
+ const char *lang = p + 6;
+ if (!lang[0]) continue;
+ /* symlinks are never built as their own tree (the default-
+ * language marker was already registered in the scan above) */
+ struct stat lst;
+ if (lstat(p, &lst) == 0 && S_ISLNK(lst.st_mode)) continue;
+ /* only a plain directory pages. */
+ struct stat st;
+ if (stat(p, &st) != 0 || !S_ISDIR(st.st_mode)) continue;
+ strbuf navl; sb_init(&navl);
+ build_nav(&navl, p, lang);
+ buildpages(&cfg, &theme, p, "dist", layout.data,
+ navl.len ? navl.data : nav_str,
+ posts_file.data, pages_file.data, lang);
+ sb_free(&navl);
+ }
+ closedir(d);
+ }
+ }
+
+ render_robots(&cfg, "dist");
+
+ /* copy any overlay/ dir verbatim into dist/ (e.g. docs/, images/,
+ * extra files the user wants deployed 1:1). */
+ if (file_exists("overlay")) copy_tree("overlay", "dist");
+
+ if (file_exists("posts")) {
+ size_t n = 0;
+ Post **posts = collectposts("posts", &n);
+ if (posts && n > 0) {
+ render_blog(&cfg, &theme, posts, n, "dist", layout.data, nav_str, posts_file.data, pages_file.data, "");
+ renderposts(&cfg, &theme, posts, n, "dist", layout.data, nav_str, posts_file.data, pages_file.data, "");
+ render_rss(&cfg, posts, n, "dist");
+ render_sitemap(&cfg, posts, n, "dist");
+ for (size_t i = 0; i < n; i++) post_free(posts[i]);
+ free(posts);
+ }
+ }
+
+ /* i18n: posts./ dirs build into dist//blog/, independent of
+ * the default posts/ (a site may be fully translated). */
+ {
+ DIR *d = opendir(".");
+ if (d) {
+ struct dirent *e;
+ while ((e = readdir(d))) {
+ if (e->d_name[0] == '.') continue;
+ const char *p = e->d_name;
+ if (strncmp(p, "posts.", 6) != 0) continue;
+ const char *lang = p + 6;
+ if (!lang[0]) continue;
+ /* symlinks (e.g. posts.en -> posts/ with pages.en set) are
+ * not separate trees — the default tree already exists */
+ struct stat lst, st;
+ if (lstat(p, &lst) == 0 && S_ISLNK(lst.st_mode)) continue;
+ if (stat(p, &st) != 0 || !S_ISDIR(st.st_mode)) continue;
+ size_t nl = 0;
+ Post **pl = collectposts(p, &nl);
+ if (pl && nl > 0) {
+ render_blog(&cfg, &theme, pl, nl, "dist", layout.data, nav_str, posts_file.data, pages_file.data, lang);
+ renderposts(&cfg, &theme, pl, nl, "dist", layout.data, nav_str, posts_file.data, pages_file.data, lang);
+ for (size_t j = 0; j < nl; j++) post_free(pl[j]);
+ free(pl);
+ }
+ }
+ closedir(d);
+ }
+ }
+
+ unlink(posts_file.data);
+ unlink(pages_file.data);
+ sb_free(&posts_file); sb_free(&pages_file);
+ sb_free(&nav);
+ sb_free(&layout);
+ sb_free(&g_tmpdir);
+ sb_free(&g_share);
+ sb_free(&g_lib);
+ sb_free(&g_font_css);
+ config_free(&theme);
+ config_free(&cfg);
+ printf("bb: built into dist/ (theme=%s)\n", g_theme);
+ return 0;
+}
diff --git a/third_party/bb/src/markdown.c b/third_party/bb/src/markdown.c
new file mode 100644
index 0000000000..fd7f9f3feb
--- /dev/null
+++ b/third_party/bb/src/markdown.c
@@ -0,0 +1,565 @@
+/* markdown.c — minimal CommonMark-subset Markdown -> HTML parser.
+ * Supports: ATX headings, paragraphs, unordered/ordered lists, fenced code
+ * blocks, indented code, blockquotes, horizontal rules, tables, and inline
+ * emphasis/strong/code/links/images. Pure C99, no dependencies.
+ *
+ * Memory-efficient: output streams directly to a FILE* (the content file),
+ * never buffered in RAM. Only one line at a time is held in memory. */
+#include "bb.h"
+#include
+#include
+#include
+#include
+
+/* ---- inline parsing ---- */
+
+/* Relative prefix ("../" * depth) prepended to root-relative links in
+ * Markdown content, so links work no matter where the site is deployed.
+ * Set per render by markdown_to_html(). */
+static const char *g_md_prefix = "";
+
+/* ---- heading anchors ---- */
+
+/* Turn a heading's text into a URL-safe anchor id: lowercase, spaces and
+ * runs of non-alphanumerics become a single '-'. Empty result -> "sec". */
+static void heading_slug(const char *s, size_t n, char *out, size_t outsz) {
+ size_t o = 0;
+ int dash = 0;
+ for (size_t i = 0; i < n && o + 1 < outsz; i++) {
+ unsigned char c = (unsigned char)s[i];
+ if (isalnum(c)) {
+ out[o++] = (char)tolower(c);
+ dash = 0;
+ } else if (!dash) {
+ out[o++] = '-';
+ dash = 1;
+ }
+ }
+ while (o > 0 && out[o - 1] == '-') o--;
+ if (o == 0) { out[o++] = 's'; out[o++] = 'e'; out[o++] = 'c'; }
+ out[o] = '\0';
+}
+
+static void inline_parse(FILE *out, const char *s, size_t n);
+
+/* Find matching closing delimiter for emphasis/strong. Returns index or n. */
+static size_t find_close(const char *s, size_t n, char c, size_t start) {
+ for (size_t i = start; i < n; i++) {
+ if (s[i] == c) return i;
+ }
+ return n;
+}
+
+/* Escape a span into a small stack buffer, then write it. */
+static void emit_escaped(FILE *out, const char *s, size_t n) {
+ for (size_t i = 0; i < n; i++) {
+ switch (s[i]) {
+ case '&': fputs("&", out); break;
+ case '<': fputs("<", out); break;
+ case '>': fputs(">", out); break;
+ case '"': fputs(""", out); break;
+ case '\'': fputs("'", out); break;
+ default: fputc(s[i], out); break;
+ }
+ }
+}
+
+static void inline_parse(FILE *out, const char *s, size_t n) {
+ size_t i = 0;
+ while (i < n) {
+ char c = s[i];
+ if (c == '\\' && i + 1 < n) {
+ fputc(s[i + 1], out);
+ i += 2;
+ continue;
+ }
+ if (c == '`') {
+ /* code span */
+ size_t j = i + 1;
+ while (j < n && s[j] == '`') j++;
+ size_t ticks = j - i;
+ size_t close = i + ticks;
+ while (close < n) {
+ if (s[close] == '`') {
+ size_t k = close;
+ size_t cnt = 0;
+ while (k < n && s[k] == '`') { cnt++; k++; }
+ if (cnt == ticks) break;
+ close = k;
+ } else {
+ close++;
+ }
+ }
+ if (close < n) {
+ fputs("", out);
+ emit_escaped(out, s + i + ticks, close - (i + ticks));
+ fputs("", out);
+ i = close + ticks;
+ continue;
+ }
+ fputc(c, out);
+ i++;
+ continue;
+ }
+ if (c == '*' || c == '_') {
+ /* emphasis or strong */
+ int strong = (i + 1 < n && s[i + 1] == c);
+ size_t delim = strong ? 2 : 1;
+ size_t close = find_close(s, n, c, i + delim);
+ if (close < n) {
+ if (strong) {
+ fputs("", out);
+ inline_parse(out, s + i + 2, close - (i + 2));
+ fputs(" ", out);
+ i = close + 2;
+ } else {
+ fputs("", out);
+ inline_parse(out, s + i + 1, close - (i + 1));
+ fputs(" ", out);
+ i = close + 1;
+ }
+ continue;
+ }
+ fputc(c, out);
+ i++;
+ continue;
+ }
+ if (c == '!') {
+ /* image:  -> */
+ if (i + 1 < n && s[i + 1] == '[') {
+ size_t close = find_close(s, n, ']', i + 2);
+ if (close < n && close + 1 < n && s[close + 1] == '(') {
+ size_t pend = close + 2;
+ while (pend < n && s[pend] != ')') pend++;
+ if (pend < n) {
+ size_t u = close + 2;
+ while (u < pend && isspace((unsigned char)s[u])) u++;
+ size_t uend = pend;
+ while (uend > u && isspace((unsigned char)s[uend - 1])) uend--;
+ fputs(" u && s[u] == '/') {
+ fputs(g_md_prefix, out);
+ emit_escaped(out, s + u + 1, uend - (u + 1));
+ } else {
+ emit_escaped(out, s + u, uend - u);
+ }
+ fputs("\" alt=\"", out);
+ emit_escaped(out, s + i + 2, close - (i + 2));
+ fputs("\">", out);
+ i = pend + 1;
+ continue;
+ }
+ }
+ }
+ fputc(c, out);
+ i++;
+ continue;
+ }
+ if (c == '[') {
+ /* link — if the text starts with , render the outer
+ * link around the image (nested image-in-link, CommonMark) */
+ if (i + 3 < n && s[i + 1] == '!' && s[i + 2] == '[') {
+ size_t iclose = find_close(s, n, ']', i + 3);
+ if (iclose < n && iclose + 1 < n && s[iclose + 1] == '(') {
+ size_t ipend = iclose + 2;
+ while (ipend < n && s[ipend] != ')') ipend++;
+ if (ipend < n) {
+ /* the outer link: next ]( after the inner url ) */
+ size_t close = find_close(s, n, ']', ipend + 1);
+ if (close < n && close + 1 < n && s[close + 1] == '(') {
+ size_t pend = close + 2;
+ while (pend < n && s[pend] != ')') pend++;
+ if (pend < n) {
+ size_t u = close + 2;
+ while (u < pend && isspace((unsigned char)s[u])) u++;
+ size_t uend = pend;
+ while (uend > u && isspace((unsigned char)s[uend - 1])) uend--;
+ fputs(" u && s[u] == '/') {
+ fputs(g_md_prefix, out);
+ emit_escaped(out, s + u + 1, uend - (u + 1));
+ } else {
+ emit_escaped(out, s + u, uend - u);
+ }
+ fputs("\">", out);
+ /* the image */
+ size_t iu = iclose + 2;
+ while (iu < ipend && isspace((unsigned char)s[iu])) iu++;
+ size_t iuend = ipend;
+ while (iuend > iu && isspace((unsigned char)s[iuend - 1])) iuend--;
+ fputs(" iu && s[iu] == '/') {
+ fputs(g_md_prefix, out);
+ emit_escaped(out, s + iu + 1, iuend - (iu + 1));
+ } else {
+ emit_escaped(out, s + iu, iuend - iu);
+ }
+ fputs("\" alt=\"", out);
+ emit_escaped(out, s + i + 3, iclose - (i + 3));
+ fputs("\"> ", out);
+ i = pend + 1;
+ continue;
+ }
+ }
+ }
+ }
+ }
+ /* link */
+ size_t close = find_close(s, n, ']', i + 1);
+ if (close < n && close + 1 < n && s[close + 1] == '(') {
+ size_t pend = close + 2;
+ while (pend < n && s[pend] != ')') pend++;
+ if (pend < n) {
+ /* extract url (trimmed) */
+ size_t u = close + 2;
+ while (u < pend && isspace((unsigned char)s[u])) u++;
+ size_t uend = pend;
+ while (uend > u && isspace((unsigned char)s[uend - 1])) uend--;
+ fputs(" u && s[u] == '/') {
+ /* root-relative link: make it page-relative */
+ fputs(g_md_prefix, out);
+ emit_escaped(out, s + u + 1, uend - (u + 1));
+ } else {
+ emit_escaped(out, s + u, uend - u);
+ }
+ fputs("\">", out);
+ inline_parse(out, s + i + 1, close - (i + 1));
+ fputs(" ", out);
+ i = pend + 1;
+ continue;
+ }
+ }
+ fputc(c, out);
+ i++;
+ continue;
+ }
+ switch (c) {
+ case '&': fputs("&", out); break;
+ case '<': fputs("<", out); break;
+ case '>': fputs(">", out); break;
+ case '"': fputs(""", out); break;
+ default: fputc(c, out); break;
+ }
+ i++;
+ }
+}
+
+/* ---- block parsing ---- */
+
+static int is_atx_heading(const char *line) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ if (line[i] != '#') return 0;
+ int j = i;
+ while (line[j] == '#') j++;
+ if (j - i > 6) return 0;
+ if (line[j] != '\0' && line[j] != ' ' && line[j] != '\t') return 0;
+ return j - i;
+}
+
+static int is_fence(const char *line, char *which) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ if (line[i] != '`' && line[i] != '~') return 0;
+ char c = line[i];
+ int j = i;
+ while (line[j] == c) j++;
+ if (j - i < 3) return 0;
+ *which = c;
+ return 1;
+}
+
+static int is_hr(const char *line) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ if (line[i] == '\0') return 0;
+ char c = line[i];
+ if (c != '-' && c != '*' && c != '_') return 0;
+ int count = 0;
+ while (line[i] != '\0') {
+ if (line[i] == c) count++;
+ else if (line[i] == ' ' || line[i] == '\t') { /* ok */ }
+ else return 0;
+ i++;
+ }
+ return count >= 3;
+}
+
+static int is_blockquote(const char *line) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ return line[i] == '>';
+}
+
+static int is_ul(const char *line) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ if (line[i] != '-' && line[i] != '*' && line[i] != '+') return 0;
+ /* require a space (or end) after the marker, else it's emphasis */
+ i++;
+ if (line[i] == '\0') return 0;
+ return line[i] == ' ' || line[i] == '\t';
+}
+
+static int is_ol(const char *line) {
+ int i = 0;
+ while (line[i] == ' ') i++;
+ if (!isdigit((unsigned char)line[i])) return 0;
+ while (isdigit((unsigned char)line[i])) i++;
+ return line[i] == '.' || line[i] == ')';
+}
+
+static int is_table_sep(const char *line) {
+ int i = 0;
+ int has_dash = 0;
+ while (line[i] != '\0') {
+ char c = line[i];
+ if (c == '|' || c == ' ' || c == '\t' || c == ':') { /* ok */ }
+ else if (c == '-') has_dash = 1;
+ else return 0;
+ i++;
+ }
+ return has_dash;
+}
+
+/* Split a table row into cells. Cells are written into a fixed array of
+ * pointers into a caller-provided buffer (no per-cell malloc). */
+static void split_cells(const char *line, char *buf, size_t bufsz,
+ char **cells, int *count, int max) {
+ *count = 0;
+ const char *p = line;
+ size_t bi = 0;
+ if (*p == '|') p++;
+ while (*p && *count < max) {
+ const char *start = p;
+ while (*p && *p != '|') p++;
+ size_t len = (size_t)(p - start);
+ while (len > 0 && isspace((unsigned char)start[0])) { start++; len--; }
+ while (len > 0 && isspace((unsigned char)start[len - 1])) len--;
+ if (bi + len + 1 <= bufsz) {
+ memcpy(buf + bi, start, len);
+ buf[bi + len] = '\0';
+ cells[*count] = buf + bi;
+ bi += len + 1;
+ (*count)++;
+ }
+ if (*p == '|') p++;
+ }
+}
+
+void markdown_to_html(FILE *out, FILE *in, const char *prefix) {
+ if (!out || !in) return;
+ g_md_prefix = prefix ? prefix : "";
+ /* read lines dynamically (getline), no fixed-size limit */
+ char *line = NULL;
+ size_t line_cap = 0;
+ int in_para = 0;
+ int in_list = 0; /* 0 none, 1 ul, 2 ol */
+ int in_blockquote = 0;
+ int in_table = 0;
+ int first_line = 1;
+
+ while (getline(&line, &line_cap, in) != -1) {
+ /* strip trailing newline */
+ size_t li = strlen(line);
+ while (li > 0 && (line[li-1] == '\n' || line[li-1] == '\r')) line[--li] = '\0';
+ const char *l = line;
+
+ /* strip YAML frontmatter on the first line — only if a closing
+ * --- is found, else it's a horizontal rule */
+ if (first_line) {
+ first_line = 0;
+ if (strncmp(l, "---", 3) == 0) {
+ long pos = ftell(in);
+ int found = 0;
+ char *pl = NULL;
+ size_t pl_cap = 0;
+ while (getline(&pl, &pl_cap, in) != -1) {
+ size_t pll = strlen(pl);
+ while (pll > 0 && (pl[pll-1] == '\n' || pl[pll-1] == '\r')) pl[--pll] = '\0';
+ if (strncmp(pl, "---", 3) == 0) { found = 1; break; }
+ }
+ free(pl);
+ if (found) {
+ if (getline(&line, &line_cap, in) == -1) break;
+ li = strlen(line);
+ while (li > 0 && (line[li-1] == '\n' || line[li-1] == '\r')) line[--li] = '\0';
+ l = line;
+ } else {
+ /* not frontmatter — rewind, treat as hr below */
+ fseek(in, pos, SEEK_SET);
+ }
+ }
+ }
+
+ /* blank line */
+ int blank = 1;
+ for (size_t i = 0; i < li; i++) {
+ if (!isspace((unsigned char)line[i])) { blank = 0; break; }
+ }
+
+ if (blank) {
+ if (in_para) { fputs("
\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (in_blockquote) { fputs("\n", out); in_blockquote = 0; }
+ if (in_table) { in_table = 0; }
+ continue;
+ }
+
+ /* fenced code */
+ char fence_char = 0;
+ if (is_fence(l, &fence_char)) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (in_blockquote) { fputs("\n", out); in_blockquote = 0; }
+ fputs("", out);
+ while (getline(&line, &line_cap, in) != -1) {
+ size_t li2 = strlen(line);
+ while (li2 > 0 && (line[li2-1] == '\n' || line[li2-1] == '\r')) line[--li2] = '\0';
+ char fc2 = 0;
+ if (is_fence(line, &fc2) && fc2 == fence_char) break;
+ emit_escaped(out, line, li2);
+ fputc('\n', out);
+ }
+ fputs(" \n", out);
+ continue;
+ }
+
+ /* ATX heading */
+ int hlevel = is_atx_heading(l);
+ if (hlevel) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (in_blockquote) { fputs("\n", out); in_blockquote = 0; }
+ if (in_table) { in_table = 0; }
+ const char *h = l;
+ while (*h == ' ') h++;
+ h += hlevel;
+ while (*h == ' ' || *h == '\t') h++;
+ size_t hlen = strlen(h);
+ while (hlen > 0 && h[hlen - 1] == '#') hlen--;
+ while (hlen > 0 && isspace((unsigned char)h[hlen - 1])) hlen--;
+ char slug[128];
+ heading_slug(h, hlen, slug, sizeof slug);
+ fprintf(out, "", hlevel, slug);
+ inline_parse(out, h, hlen);
+ fprintf(out, " \n", hlevel);
+ continue;
+ }
+
+ /* horizontal rule */
+ if (is_hr(l)) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (in_blockquote) { fputs("\n", out); in_blockquote = 0; }
+ if (in_table) { in_table = 0; }
+ fputs(" \n", out);
+ continue;
+ }
+
+ /* blockquote */
+ if (is_blockquote(l)) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (!in_blockquote) { fputs("\n", out); in_blockquote = 1; }
+ const char *q = l;
+ while (*q == ' ') q++;
+ if (*q == '>') q++;
+ if (*q == ' ') q++;
+ fputs("", out);
+ inline_parse(out, q, strlen(q));
+ fputs("
\n", out);
+ continue;
+ }
+
+ /* table separator */
+ if (in_table && is_table_sep(l)) {
+ continue;
+ }
+
+ /* table header start: a line with | and a following separator */
+ if (!in_table && strchr(l, '|')) {
+ /* peek next line to see if it's a separator */
+ long pos = ftell(in);
+ char *next = NULL;
+ size_t next_cap = 0;
+ if (getline(&next, &next_cap, in) != -1) {
+ size_t ni = strlen(next);
+ while (ni > 0 && (next[ni-1] == '\n' || next[ni-1] == '\r')) next[--ni] = '\0';
+ if (is_table_sep(next)) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_list) { fputs(in_list == 1 ? "\n" : "\n", out); in_list = 0; }
+ if (in_blockquote) { fputs(" \n", out); in_blockquote = 0; }
+ in_table = 1;
+ fputs("\n\n\n", out);
+ char cells[64][128];
+ char *cellp[64];
+ int n = 0;
+ split_cells(l, (char *)cells, sizeof(cells), cellp, &n, 64);
+ for (int i = 0; i < n; i++) {
+ fputs("", out);
+ inline_parse(out, cellp[i], strlen(cellp[i]));
+ fputs(" \n", out);
+ }
+ fputs(" \n \n\n", out);
+ free(next);
+ continue;
+ }
+ /* not a table: rewind and fall through */
+ fseek(in, pos, SEEK_SET);
+ free(next);
+ }
+ }
+
+ /* table body row */
+ if (in_table && strchr(l, '|')) {
+ fputs("\n", out);
+ char cells[64][128];
+ char *cellp[64];
+ int n = 0;
+ split_cells(l, (char *)cells, sizeof(cells), cellp, &n, 64);
+ for (int i = 0; i < n; i++) {
+ fputs("", out);
+ inline_parse(out, cellp[i], strlen(cellp[i]));
+ fputs(" \n", out);
+ }
+ fputs(" \n", out);
+ continue;
+ }
+
+ /* list item */
+ int is_ul_item = is_ul(l);
+ int is_ol_item = is_ol(l);
+ if (is_ul_item || is_ol_item) {
+ if (in_para) { fputs("\n", out); in_para = 0; }
+ if (in_blockquote) { fputs("\n", out); in_blockquote = 0; }
+ if (in_table) { in_table = 0; }
+ int want = is_ul_item ? 1 : 2;
+ if (in_list != want) {
+ if (in_list) fputs(in_list == 1 ? "\n" : "\n", out);
+ fputs(want == 1 ? "\n" : "\n", out);
+ in_list = want;
+ }
+ const char *item = l;
+ while (*item == ' ') item++;
+ if (is_ul_item) { item++; while (*item == ' ') item++; }
+ else { while (isdigit((unsigned char)*item)) item++; if (*item=='.'||*item==')') item++; while (*item==' ') item++; }
+ fputs("", out);
+ inline_parse(out, item, strlen(item));
+ fputs(" \n", out);
+ continue;
+ }
+
+ /* paragraph */
+ if (!in_para) { fputs("", out); in_para = 1; }
+ else fputc('\n', out);
+ inline_parse(out, l, li);
+ }
+
+ free(line);
+ if (in_para) fputs("
\n", out);
+ if (in_list) fputs(in_list == 1 ? " \n" : "\n", out);
+ if (in_blockquote) fputs("\n", out);
+ if (in_table) fputs(" \n
\n", out);
+}
diff --git a/third_party/bb/src/post.c b/third_party/bb/src/post.c
new file mode 100644
index 0000000000..3156d6bbfd
--- /dev/null
+++ b/third_party/bb/src/post.c
@@ -0,0 +1,216 @@
+/* post.c — blog post parsing.
+ * Format: _posts/YYYY-MM-DD-slug.md with optional YAML frontmatter:
+ * ---
+ * title: "..."
+ * excerpt: "..."
+ * ---
+ * body markdown
+ */
+#include "bb.h"
+#include
+#include
+#include
+
+Post *post_new(void) {
+ Post *p = calloc(1, sizeof(Post));
+ return p;
+}
+
+void post_free(Post *p) {
+ if (!p) return;
+ free(p->date);
+ free(p->slug);
+ free(p->title);
+ free(p->excerpt);
+ free(p->robots);
+ free(p->content);
+ config_free(&p->fm);
+ free(p);
+}
+
+/* Extract a YAML frontmatter value for a key. Returns malloc'd string or NULL. */
+static char *frontmatter_get(const char *fm, const char *key) {
+ size_t klen = strlen(key);
+ const char *p = fm;
+ while (*p) {
+ /* line start */
+ if (strncmp(p, key, klen) == 0 && p[klen] == ':') {
+ const char *v = p + klen + 1;
+ while (*v == ' ' || *v == '\t') v++;
+ /* strip quotes */
+ if (*v == '"') {
+ v++;
+ const char *end = strchr(v, '"');
+ if (end) {
+ size_t len = (size_t)(end - v);
+ char *out = malloc(len + 1);
+ if (out) { memcpy(out, v, len); out[len] = '\0'; }
+ return out;
+ }
+ }
+ /* unquoted: to end of line */
+ const char *end = v;
+ while (*end && *end != '\n') end++;
+ while (end > v && isspace((unsigned char)end[-1])) end--;
+ size_t len = (size_t)(end - v);
+ char *out = malloc(len + 1);
+ if (out) { memcpy(out, v, len); out[len] = '\0'; }
+ return out;
+ }
+ /* next line */
+ const char *nl = strchr(p, '\n');
+ if (!nl) break;
+ p = nl + 1;
+ }
+ return NULL;
+}
+
+/* Parse a frontmatter block (key: value lines) into a config.
+ * fm is a NUL-terminated string of the block between the --- markers. */
+static void frontmatter_parse_str(const char *fm, config *out) {
+ const char *p = fm;
+ while (*p) {
+ /* skip to line start */
+ while (*p == '\n') p++;
+ if (!*p) break;
+ const char *eol = strchr(p, '\n');
+ size_t len = eol ? (size_t)(eol - p) : strlen(p);
+ /* trim */
+ const char *s = p;
+ size_t slen = len;
+ while (slen > 0 && (*s == ' ' || *s == '\t')) { s++; slen--; }
+ while (slen > 0 && (s[slen-1] == ' ' || s[slen-1] == '\t' || s[slen-1] == '\r')) slen--;
+ if (slen > 0 && s[0] != '#') {
+ const char *colon = memchr(s, ':', slen);
+ if (colon) {
+ size_t klen = (size_t)(colon - s);
+ const char *v = colon + 1;
+ size_t vlen = slen - klen - 1;
+ while (vlen > 0 && (*v == ' ' || *v == '\t')) { v++; vlen--; }
+ while (vlen > 0 && (v[vlen-1] == ' ' || v[vlen-1] == '\t')) vlen--;
+ /* strip quotes */
+ if (vlen >= 2 && v[0] == '"' && v[vlen-1] == '"') { v++; vlen -= 2; }
+ char *key = malloc(klen + 1);
+ char *val = malloc(vlen + 1);
+ if (key && val) {
+ memcpy(key, s, klen); key[klen] = '\0';
+ memcpy(val, v, vlen); val[vlen] = '\0';
+ config_add(out, key, val);
+ }
+ free(key);
+ free(val);
+ }
+ }
+ p = eol ? eol + 1 : p + len;
+ }
+}
+
+/* Parse all frontmatter key/value pairs from a .md file into a config.
+ * Returns 0 on success (even if no frontmatter), -1 on read error. */
+int frontmatter_load(const char *path, config *out) {
+ config_init(out);
+ FILE *f = fopen(path, "rb");
+ if (!f) return -1;
+ char *line = NULL;
+ size_t cap = 0;
+ ssize_t n = getline(&line, &cap, f);
+ if (n < 0 || strncmp(line, "---", 3) != 0) {
+ free(line);
+ fclose(f);
+ return 0; /* no frontmatter */
+ }
+ free(line);
+ line = NULL;
+ cap = 0;
+ /* read until closing --- */
+ strbuf fm; sb_init(&fm);
+ while ((n = getline(&line, &cap, f)) >= 0) {
+ if (strncmp(line, "---", 3) == 0) break;
+ sb_append_n(&fm, line, (size_t)n);
+ }
+ free(line);
+ fclose(f);
+ frontmatter_parse_str(fm.data, out);
+ sb_free(&fm);
+ return 0;
+}
+
+/* Read a frontmatter value from any .md file (pages and posts).
+ * Returns malloc'd string or NULL if the key is absent. */
+char *frontmatter_value(const char *path, const char *key) {
+ config fm;
+ if (frontmatter_load(path, &fm) != 0) return NULL;
+ const char *v = config_get(&fm, key);
+ char *out = v ? strdup(v) : NULL;
+ config_free(&fm);
+ return out;
+}
+
+Post *post_parse(const char *path) {
+ char *raw = NULL;
+ FILE *f = fopen(path, "rb");
+ if (!f) return NULL;
+ fseek(f, 0, SEEK_END);
+ long sz = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ if (sz < 0) { fclose(f); return NULL; }
+ raw = malloc((size_t)sz + 1);
+ if (!raw) { fclose(f); return NULL; }
+ size_t rd = fread(raw, 1, (size_t)sz, f);
+ raw[rd] = '\0';
+ fclose(f);
+
+ Post *p = post_new();
+ if (!p) { free(raw); return NULL; }
+ config_init(&p->fm);
+
+ /* filename: YYYY-MM-DD-slug.md */
+ const char *base = strrchr(path, '/');
+ base = base ? base + 1 : path;
+ size_t blen = strlen(base);
+ if (blen >= 3 && strcmp(base + blen - 3, ".md") == 0) {
+ /* date = first 10 chars if they look like YYYY-MM-DD */
+ if (blen >= 10 && base[4] == '-' && base[7] == '-') {
+ p->date = malloc(11);
+ if (p->date) { memcpy(p->date, base, 10); p->date[10] = '\0'; }
+ /* slug = after date + dash, before .md */
+ const char *slug_start = base + 11;
+ size_t slug_len = blen - 3 - (size_t)(slug_start - base);
+ if (slug_len > 0) {
+ p->slug = malloc(slug_len + 1);
+ if (p->slug) { memcpy(p->slug, slug_start, slug_len); p->slug[slug_len] = '\0'; }
+ }
+ }
+ }
+
+ /* frontmatter */
+ const char *body = raw;
+ if (strncmp(raw, "---", 3) == 0) {
+ const char *fm_end = strstr(raw + 3, "\n---");
+ if (fm_end) {
+ /* frontmatter block between raw+3 and fm_end */
+ size_t fm_len = (size_t)(fm_end - (raw + 3));
+ char *fm = malloc(fm_len + 1);
+ if (fm) {
+ memcpy(fm, raw + 3, fm_len);
+ fm[fm_len] = '\0';
+ frontmatter_parse_str(fm, &p->fm);
+ p->title = frontmatter_get(fm, "title");
+ p->excerpt = frontmatter_get(fm, "excerpt");
+ p->robots = frontmatter_get(fm, "robots");
+ free(fm);
+ }
+ body = fm_end + 4; /* skip \n--- */
+ if (*body == '\n') body++;
+ }
+ }
+
+ /* content = rest */
+ p->content = strdup(body);
+
+ /* fallback title = slug */
+ if (!p->title && p->slug) p->title = strdup(p->slug);
+
+ free(raw);
+ return p;
+}
diff --git a/third_party/bb/src/serve.c b/third_party/bb/src/serve.c
new file mode 100644
index 0000000000..542475640d
--- /dev/null
+++ b/third_party/bb/src/serve.c
@@ -0,0 +1,319 @@
+/* serve.c — `bb serve`: tiny static HTTP server for previewing dist/.
+ * Usage: bb serve [--port N] [--bind ADDR] [--dir DIR]
+ * GET and HEAD only, one forked child per connection, no keep-alive.
+ * Meant for local preview, not for the open internet. C99 + POSIX. */
+#define _XOPEN_SOURCE 700 /* realpath() under strict -std=c99 */
+#include "bb.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define REQ_MAX 8192
+
+static const struct { const char *ext, *type; } mime_types[] = {
+ { "html", "text/html; charset=utf-8" },
+ { "htm", "text/html; charset=utf-8" },
+ { "css", "text/css; charset=utf-8" },
+ { "js", "text/javascript; charset=utf-8" },
+ { "json", "application/json" },
+ { "xml", "application/xml" },
+ { "txt", "text/plain; charset=utf-8" },
+ { "svg", "image/svg+xml" },
+ { "png", "image/png" },
+ { "jpg", "image/jpeg" },
+ { "jpeg", "image/jpeg" },
+ { "gif", "image/gif" },
+ { "webp", "image/webp" },
+ { "ico", "image/x-icon" },
+ { "woff", "font/woff" },
+ { "woff2","font/woff2" },
+ { "ttf", "font/ttf" },
+ { "otf", "font/otf" },
+ { "pdf", "application/pdf" },
+ { NULL, NULL }
+};
+
+static const char *mime_for(const char *path) {
+ const char *dot = strrchr(path, '.');
+ const char *slash = strrchr(path, '/');
+ if (!dot || (slash && dot < slash)) return "application/octet-stream";
+ dot++;
+ for (int i = 0; mime_types[i].ext; i++)
+ if (strcmp(dot, mime_types[i].ext) == 0) return mime_types[i].type;
+ return "application/octet-stream";
+}
+
+static int write_all(int fd, const char *buf, size_t n) {
+ while (n > 0) {
+ ssize_t w = write(fd, buf, n);
+ if (w < 0) {
+ if (errno == EINTR) continue;
+ return -1;
+ }
+ buf += w;
+ n -= (size_t)w;
+ }
+ return 0;
+}
+
+/* Send a complete small response (status line, headers, body). */
+static void respond(int fd, int head_only, int code, const char *reason,
+ const char *extra, const char *body) {
+ strbuf out; sb_init(&out);
+ size_t blen = body ? strlen(body) : 0;
+ sb_printf(&out,
+ "HTTP/1.0 %d %s\r\n"
+ "Content-Type: text/html; charset=utf-8\r\n"
+ "Content-Length: %lu\r\n"
+ "%s"
+ "Connection: close\r\n\r\n",
+ code, reason, (unsigned long)blen, extra ? extra : "");
+ if (!head_only && body) sb_append(&out, body);
+ write_all(fd, out.data, out.len);
+ sb_free(&out);
+}
+
+static void respond_error(int fd, int head_only, int code, const char *reason) {
+ strbuf body; sb_init(&body);
+ sb_printf(&body,
+ "\n"
+ "%d %s \n"
+ "%d %s \n",
+ code, reason, code, reason);
+ respond(fd, head_only, code, reason, NULL, body.data);
+ sb_free(&body);
+}
+
+static int hexval(int c) {
+ if (c >= '0' && c <= '9') return c - '0';
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+ return -1;
+}
+
+/* Decode %XX in place. Returns 0 on success, -1 on bad escape or NUL. */
+static int url_decode(char *s) {
+ char *w = s;
+ for (const char *r = s; *r; r++) {
+ if (*r == '%') {
+ int h = hexval((unsigned char)r[1]);
+ int l = h >= 0 ? hexval((unsigned char)r[2]) : -1;
+ if (h < 0 || l < 0) return -1;
+ int c = h * 16 + l;
+ if (c == 0) return -1;
+ *w++ = (char)c;
+ r += 2;
+ } else {
+ *w++ = *r;
+ }
+ }
+ *w = '\0';
+ return 0;
+}
+
+/* True if any path segment is "..". */
+static int has_dotdot(const char *p) {
+ while (*p) {
+ while (*p == '/') p++;
+ const char *seg = p;
+ while (*p && *p != '/') p++;
+ if (p - seg == 2 && seg[0] == '.' && seg[1] == '.') return 1;
+ }
+ return 0;
+}
+
+static void handle(int fd, const char *root) {
+ struct timeval tv = { 10, 0 };
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
+
+ char req[REQ_MAX + 1];
+ size_t got = 0;
+ while (got < REQ_MAX) {
+ ssize_t r = read(fd, req + got, REQ_MAX - got);
+ if (r < 0 && errno == EINTR) continue;
+ if (r <= 0) break;
+ got += (size_t)r;
+ req[got] = '\0';
+ if (strstr(req, "\r\n\r\n") || strstr(req, "\n\n")) break;
+ }
+ req[got] = '\0';
+ char *eol = strpbrk(req, "\r\n");
+ if (!eol) { respond_error(fd, 0, 400, "Bad Request"); return; }
+ *eol = '\0';
+
+ char *method = req;
+ char *target = strchr(method, ' ');
+ if (!target) { respond_error(fd, 0, 400, "Bad Request"); return; }
+ *target++ = '\0';
+ char *ver = strchr(target, ' ');
+ if (!ver) { respond_error(fd, 0, 400, "Bad Request"); return; }
+ *ver = '\0';
+
+ int head = strcmp(method, "HEAD") == 0;
+ if (!head && strcmp(method, "GET") != 0) {
+ respond(fd, 0, 405, "Method Not Allowed", "Allow: GET, HEAD\r\n",
+ "405 Method Not Allowed \n");
+ fprintf(stderr, "%s %s -> 405\n", method, target);
+ return;
+ }
+
+ char *q = strpbrk(target, "?#");
+ if (q) *q = '\0';
+ char logpath[256];
+ snprintf(logpath, sizeof logpath, "%s", target);
+
+ if (target[0] != '/' || url_decode(target) != 0 || has_dotdot(target)) {
+ respond_error(fd, head, 400, "Bad Request");
+ fprintf(stderr, "%s %s -> 400\n", method, logpath);
+ return;
+ }
+
+ strbuf path; sb_init(&path);
+ sb_printf(&path, "%s%s", root, target);
+ struct stat st;
+ if (stat(path.data, &st) == 0 && S_ISDIR(st.st_mode)) {
+ size_t tl = strlen(target);
+ if (target[tl - 1] != '/') {
+ strbuf loc; sb_init(&loc);
+ sb_printf(&loc, "Location: %s/\r\n", logpath);
+ respond(fd, head, 301, "Moved Permanently", loc.data, "");
+ sb_free(&loc);
+ sb_free(&path);
+ fprintf(stderr, "%s %s -> 301\n", method, logpath);
+ return;
+ }
+ sb_append(&path, "index.html");
+ }
+
+ /* Resolve symlinks and make sure the result is still inside root. */
+ char *real = realpath(path.data, NULL);
+ sb_free(&path);
+ size_t rl = strlen(root);
+ if (!real || strncmp(real, root, rl) != 0 ||
+ (real[rl] != '/' && real[rl] != '\0') ||
+ stat(real, &st) != 0 || !S_ISREG(st.st_mode)) {
+ free(real);
+ respond_error(fd, head, 404, "Not Found");
+ fprintf(stderr, "%s %s -> 404\n", method, logpath);
+ return;
+ }
+ FILE *f = fopen(real, "rb");
+ if (!f) {
+ free(real);
+ respond_error(fd, head, 403, "Forbidden");
+ fprintf(stderr, "%s %s -> 403\n", method, logpath);
+ return;
+ }
+
+ strbuf hdr; sb_init(&hdr);
+ sb_printf(&hdr,
+ "HTTP/1.0 200 OK\r\n"
+ "Content-Type: %s\r\n"
+ "Content-Length: %lu\r\n"
+ "Cache-Control: no-cache\r\n"
+ "Connection: close\r\n\r\n",
+ mime_for(real), (unsigned long)st.st_size);
+ int ok = write_all(fd, hdr.data, hdr.len) == 0;
+ sb_free(&hdr);
+ if (ok && !head) {
+ char buf[16384];
+ size_t n;
+ while ((n = fread(buf, 1, sizeof buf, f)) > 0)
+ if (write_all(fd, buf, n) != 0) break;
+ }
+ fclose(f);
+ free(real);
+ fprintf(stderr, "%s %s -> 200\n", method, logpath);
+}
+
+int cmd_serve(int argc, char **argv) {
+ const char *port = "8000", *bind_addr = "127.0.0.1", *dir = "dist";
+ for (int i = 2; i < argc; i++) {
+ if (strcmp(argv[i], "--port") == 0 && i + 1 < argc) {
+ port = argv[++i];
+ char *end;
+ long p = strtol(port, &end, 10);
+ if (*end || p < 1 || p > 65535) {
+ fprintf(stderr, "bb: invalid port '%s'\n", port);
+ return 1;
+ }
+ } else if (strcmp(argv[i], "--bind") == 0 && i + 1 < argc) {
+ bind_addr = argv[++i];
+ } else if (strcmp(argv[i], "--dir") == 0 && i + 1 < argc) {
+ dir = argv[++i];
+ } else {
+ fprintf(stderr, "bb: usage: bb serve [--port N] [--bind ADDR] [--dir DIR]\n");
+ return 1;
+ }
+ }
+
+ char *root = realpath(dir, NULL);
+ struct stat st;
+ if (!root || stat(root, &st) != 0 || !S_ISDIR(st.st_mode)) {
+ fprintf(stderr, "bb: '%s' not found -- run `bb build` first\n", dir);
+ free(root);
+ return 1;
+ }
+
+ struct addrinfo hints, *res;
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+ int gai = getaddrinfo(bind_addr, port, &hints, &res);
+ if (gai != 0) {
+ fprintf(stderr, "bb: cannot resolve '%s': %s\n", bind_addr, gai_strerror(gai));
+ free(root);
+ return 1;
+ }
+ int lfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (lfd < 0) {
+ perror("bb: socket");
+ freeaddrinfo(res); free(root);
+ return 1;
+ }
+ int one = 1;
+ setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one);
+ if (bind(lfd, res->ai_addr, res->ai_addrlen) != 0 || listen(lfd, 16) != 0) {
+ fprintf(stderr, "bb: cannot listen on %s:%s: %s\n", bind_addr, port, strerror(errno));
+ close(lfd); freeaddrinfo(res); free(root);
+ return 1;
+ }
+ freeaddrinfo(res);
+
+ signal(SIGPIPE, SIG_IGN);
+ struct sigaction sa;
+ memset(&sa, 0, sizeof sa);
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = SA_NOCLDWAIT | SA_RESTART;
+ sigaction(SIGCHLD, &sa, NULL);
+
+ fprintf(stderr, "bb: serving %s at http://%s:%s/ (Ctrl-C to stop)\n",
+ dir, bind_addr, port);
+ for (;;) {
+ int cfd = accept(lfd, NULL, NULL);
+ if (cfd < 0) {
+ if (errno == EINTR) continue;
+ perror("bb: accept");
+ break;
+ }
+ pid_t pid = fork();
+ if (pid == 0) {
+ close(lfd);
+ handle(cfd, root);
+ close(cfd);
+ _exit(0);
+ }
+ close(cfd);
+ }
+ close(lfd);
+ free(root);
+ return 1;
+}
diff --git a/third_party/bb/src/strbuf.c b/third_party/bb/src/strbuf.c
new file mode 100644
index 0000000000..5aed232b5e
--- /dev/null
+++ b/third_party/bb/src/strbuf.c
@@ -0,0 +1,76 @@
+/* strbuf.c — growable string buffer */
+#include "bb.h"
+#include
+#include
+#include
+#include
+
+void sb_init(strbuf *sb) {
+ sb->data = NULL;
+ sb->len = 0;
+ sb->cap = 0;
+}
+
+void sb_free(strbuf *sb) {
+ free(sb->data);
+ sb->data = NULL;
+ sb->len = 0;
+ sb->cap = 0;
+}
+
+static int sb_reserve(strbuf *sb, size_t extra) {
+ if (sb->len + extra + 1 <= sb->cap) return 0;
+ size_t ncap = sb->cap ? sb->cap : 64;
+ while (ncap < sb->len + extra + 1) ncap *= 2;
+ char *nd = realloc(sb->data, ncap);
+ if (!nd) return -1;
+ sb->data = nd;
+ sb->cap = ncap;
+ return 0;
+}
+
+void sb_append_n(strbuf *sb, const char *s, size_t n) {
+ if (sb_reserve(sb, n) != 0) return;
+ memcpy(sb->data + sb->len, s, n);
+ sb->len += n;
+ sb->data[sb->len] = '\0';
+}
+
+void sb_append(strbuf *sb, const char *s) {
+ if (!s) return;
+ sb_append_n(sb, s, strlen(s));
+}
+
+void sb_append_char(strbuf *sb, char c) {
+ if (sb_reserve(sb, 1) != 0) return;
+ sb->data[sb->len++] = c;
+ sb->data[sb->len] = '\0';
+}
+
+void sb_printf(strbuf *sb, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ va_list ap2;
+ va_copy(ap2, ap);
+ int n = vsnprintf(NULL, 0, fmt, ap);
+ va_end(ap);
+ if (n < 0) { va_end(ap2); return; }
+ if (sb_reserve(sb, (size_t)n) != 0) { va_end(ap2); return; }
+ vsnprintf(sb->data + sb->len, (size_t)n + 1, fmt, ap2);
+ va_end(ap2);
+ sb->len += (size_t)n;
+}
+
+void html_escape(strbuf *out, const char *s) {
+ if (!s) return;
+ for (; *s; s++) {
+ switch (*s) {
+ case '&': sb_append(out, "&"); break;
+ case '<': sb_append(out, "<"); break;
+ case '>': sb_append(out, ">"); break;
+ case '"': sb_append(out, """); break;
+ case '\'': sb_append(out, "'"); break;
+ default: sb_append_char(out, *s); break;
+ }
+ }
+}
diff --git a/third_party/bb/src/template.c b/third_party/bb/src/template.c
new file mode 100644
index 0000000000..2dfa525dd2
--- /dev/null
+++ b/third_party/bb/src/template.c
@@ -0,0 +1,83 @@
+/* template.c — /bin/sh templating engine.
+ *
+ * Modeled on Konrad's tmpl(1) (https://github.com/lotherk/tmpl): run a sh
+ * script with env vars, capture stdout, stream it to the destination.
+ *
+ * Memory-efficient: stdout is streamed straight to the destination FILE*
+ * (the dist output file), never buffered in RAM. Only one line at a time
+ * is held in memory.
+ *
+ * Content is passed via a temp file (CONTENT_FILE) to avoid shell-quoting
+ * issues with large HTML blobs.
+ *
+ * The render shell is compiled in via BB_SHELL (default /bin/sh) and can be
+ * overridden at build time: make SHELL=/bin/bash.
+ *
+ * The environment is passed to the child via execve(2) — never setenv(3) —
+ * so frontmatter vars (FM_*) from one page cannot leak into the next.
+ */
+#include "bb.h"
+#include
+#include
+#include
+#include
+#include
+
+#ifndef BB_SHELL
+#define BB_SHELL "/bin/sh"
+#endif
+
+int template_run(const char *script_path, char *const envp[], FILE *out) {
+ /* find BB_LIB in envp (we never setenv, so getenv won't see it) */
+ const char *lib = NULL;
+ for (size_t i = 0; envp && envp[i]; i++) {
+ if (strncmp(envp[i], "BB_LIB=", 7) == 0) { lib = envp[i] + 7; break; }
+ }
+ /* argv: -c '. "$BB_LIB"; . "$1"'