CommonMark 0.31.2: 652/652 spec examples.
Static site builder. Markdown in; .html, .md and .txt out for every page.
One C++17 binary, no dependencies. Made for sites served with content negotiation (browsers get
HTML, curl gets text, Accept: text/markdown gets markdown), but the output is plain files that
any static host serves.
cmake -B build && cmake --build build
./build/ssg path/to/content
- Three outputs per page:
foo.mdbecomesfoo/index.html,foo/index.md(templates resolved, frontmatter gone) andfoo/index.txt(wrapped plain text). - Markdown: CommonMark 0.31.2 (all 652 spec examples), plus GFM tables, task lists,
strikethrough, bare autolinks and footnotes, and definition lists,
> [!NOTE]alerts,:::containers,==mark==, heading ids and{#id .class}attributes.extensions = falsegives strict CommonMark. - Raw HTML on by default, through an allow-list: only known-harmless tags and attributes pass;
<script>,<iframe>,<svg>, custom elements and the like are escaped (shown as text) andon*=attributes andjavascript:URLs are dropped unlessscripts = true.allow_tagsandallow_attrsextend the list. Symlinks to files are skipped unlessfollow_symlinks = true. - Templates:
{{key}},{{extend "base"}},{{include "partial"}},{{if key}}/{{if not key}}/{{else}}/{{end}},\{{escapes. Layouts nest. - Built-in keys:
url,path,build_date,word_count,reading_time,toc,children,parent_*,prev_*,next_*,canonical_url,og_title, anddata.<file>.<key>fromdata/*.tomlanddata/*.json. Series and sections need no config: sort byorder, thendate. - One HTML skeleton per site:
<title>and<main>are filled in,{{key}}is HTML-escaped. - Drafts (
draft: "true", built with--drafts), scheduled pages (adateafter the build date, unlessfuture = true),sitemap.xml(whenbase_urlis set),--check-links. - Generated files:
feed.xml(Atom, from[feed]),_redirects(fromredirects.txt, with optional meta-refresh pages), a defaultrobots.txt; a hand-written file of the same name wins. - CSS, opt-in:
{{asset "style.css"}}links a content-hashed copy (style.<hash>.css),{{inline "style.css"}}embeds it in a<style>(its CSP hash goes in the manifest), and[css] minify = trueruns a conservative minifier. - Lists without loops:
[taxonomy.tags]makes/tags/and/tags/<term>/pages, andpaginate: "10"splits an index page's{{children}}into/dir/page/2/, ...; both hand their lists to templates as Markdown-valued keys. Seeexample/blog/. manifest.jsonbeside dist: every page, its outputs and content types, assets (schema 1, see docs).- Plugins (protocol 1):
[plugin.<name>]runs an externalssg-plugin-<name>that speaks JSON lines, with hooks for the Markdown,:::containers, finished pages, assets and the finished build. Three come in the box:highlight(code blocks),images(resized copies; needs ImageMagick orsips) andsearch(a JSON index). See docs/plugins.md. - Publishing rules: everything that isn't markdown is copied as is. Hidden files (
.git,.env, ...) never ship except.well-known/. Nested git checkouts are skipped unlessnested_repos = true..assetignorefiles andignore = [...]follow gitignore rules exactly. - Safe output dir: dist is emptied before each build only if ssg created it (it holds a
.ssg-distmarker). A dist that is, or contains, the sources is refused. - Reproducible: with
SOURCE_DATE_EPOCHset (it setsbuild_date), the same input gives byte-identical output.
Needs CMake 3.16+ and a C++17 compiler.
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build # /usr/local: bin/ssg, share/man/man1/ssg.1, man5/ssg.5
cmake --install build --prefix ~/.local # or anywhere else
compile_commands.json is written to build/ for editors and clangd.
ssg --version prints the version and the commit CMake saw when it configured, e.g.
ssg 1.0.0-dev (abc1234). Release builds set the suffix: -DSSG_VERSION_SUFFIX=-alpha.1, or
"" for a final release.
Build options (all off by default except SSG_PLUGINS):
| option | effect |
|---|---|
-DSSG_PLUGINS=OFF |
Skip building and installing the first-party plugins (on by default). |
-DSSG_WERROR=ON |
Warnings are errors (-Werror, /WX). CI builds with it. |
-DSSG_SANITIZE=ON |
AddressSanitizer and UndefinedBehaviorSanitizer (GCC or Clang). |
-DSSG_FUZZ=ON |
libFuzzer targets in fuzz/; needs LLVM clang. See fuzz/README.md. |
-DSSG_FUZZ_STANDALONE=ON |
The same targets as plain programs that replay input files, with any compiler. |
mkdir -p mysite && cd mysite
cat > site.toml <<'EOF'
dist = "dist"
templates = "templates"
skeleton = "skeleton.html"
EOF
cat > skeleton.html <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<main>
</main>
</body>
</html>
EOF
cat > index.md <<'EOF'
---
title: "Hello"
---
# Hello
First page.
EOF
ssg .
ssg: built 1 page, copied 0 files in 5 ms
dist/.ssg-dist
dist/index.html
dist/index.md
dist/index.txt
dist/index.html is the skeleton with <title>Hello</title> and the page in <main>. The
templates dir may be missing until a page uses {{extend}} or {{include}}.
Preview with any static server, e.g. python3 -m http.server -d dist. Next:
docs/getting-started.md adds templates, a series with navigation, a
table of contents, and deployment.
| docs/getting-started.md | Tutorial: first site to deployed site, Cloudflare Workers and nginx configs |
| docs/configuration.md | site.toml, publishing rules, .assetignore, dist and cleaning |
| docs/templates.md | Frontmatter, template syntax, built-in keys, the skeleton, navigation |
| docs/markdown.md | Markdown dialect, extensions, sanitizing, plain-text output |
| docs/plugins.md | The plugin protocol, hooks, failures, and the first-party plugins |
| docs/deploy.md | Cloudflare, Vercel and nginx adapters (--target) and the headers they send |
| docs/cli.md | Commands, flags, exit codes, messages |
| docs/stability.md | What 1.x freezes |
| docs/migrating-from-0.2.md | Upgrading a 0.2 site; see also CHANGELOG.md |
| man/ssg.1, man/ssg.5 | Manual pages: the command, and the site format (man ssg, man 5 ssg once installed) |
docs/README.md indexes the docs. example/ is a complete site
that uses most features.
ssg [build] [--drafts] [--check-links] [--incremental] [--target <name>] [options] [<content-dir>]
ssg init|serve|watch|check|list|clean|doctor [options] [<dir>]
ssg new <path>
ssg plugins list | plugins meta <name>
ssg render [--strict] [--text] [--no-html] [--scripts|--no-scripts] [--no-extensions] <file|->
ssg completions bash|zsh|fish
ssg --help | --version
ssg <dir> is ssg build <dir>. --incremental keeps dist and rewrites only changed files. Global options: --config, --output, --base-url,
--verbose, --quiet, --color, --json, --fail-on-warning, --no-plugins. Exit status: 0
ok, 1 error, 2 usage, 3 warnings with --fail-on-warning.
Errors print ssg: <message>, prefixed with the file at fault where there is one
(ssg: guide/a.md: missing template "post" (looked for ...)), and exit 1. Bad usage prints the
usage and exits 2. Warnings (ssg: warning: ...) and notes (ssg: note: ...) don't change the
exit status unless you pass --fail-on-warning (then 3). See docs/cli.md.
cmake -B build && cmake --build build && (cd build && ctest --output-on-failure)
sh tests/run.sh build/ssg # the "sites" ctest on its own
sh tests/run.sh build/ssg --update # regenerate tests/expected/example after an intended change
tests/run.sh:
- builds
example/(withSOURCE_DATE_EPOCH=0) and diffs it againsttests/expected/example/; - runs each
tests/sites/<name>.check, a sh snippet that builds a scratch copy oftests/sites/<name>/(or a site it writes itself) and asserts on dist and stderr; - renders each
tests/markdown/X.mdand compares it withX.htmland (--text)X.txt.--updatenever touches these.
The unit ctest (tests/unit/config_test.cpp) checks what site.toml loading stores that the
build output doesn't show, such as the [plugin.<name>] tables. json_test covers the JSON reader the
plugin protocol uses, and tests/plugin/mock_plugin.cpp is the plugin that tests/sites/plugin.check
drives through every hook and failure.
CommonMark conformance needs the spec, which isn't vendored:
curl -o tests/spec.json https://spec.commonmark.org/0.31.2/spec.json
python3 tests/commonmark.py build/ssg tests/spec.json # --section, --example N, --verbose
If tests/spec.json and Python 3 are present when CMake configures, this is also the
commonmark ctest, which requires 100%. CI fetches the spec (checking its sha256) and runs every
test on Linux (GCC, Clang) and macOS in Debug and Release, plus a sanitizer build and 60 seconds
of each fuzz target: .github/workflows/ci.yml.