Purpose
site builds linked HTML pages from a Markdown directory or a .yaml or
.yml site config. Directory mode recursively discovers regular .md and
.markdown files, rewrites valid Markdown links, and validates anchors and
local images. It does not read stdin.
Input and output
Directory mode requires --output-dir. The destination must not already
exist. --assets local copies validated assets; inline embeds supported
images. On success, the new directory contains page artifacts, required runtime
assets, and margo-manifest.json.
The report on stdout contains margo-site-report/v1, artifact count, manifest
digest, page records, and an optional policy digest. Build and publication
failures go to stderr.
Raw HTML and iframe markup are denied by default. Add
--allow-unsafe-html (or --allow-raw-html) for a deliberately embedded HTML
surface; this is a process-level opt-in and is not stored in site.yaml.
Enable --math when building a site containing equations. The flag applies
throughout the build, including requested PDF downloads, and the site emits
local math assets only where needed. This option is not stored in YAML. See
Math and LaTeX for syntax and examples.
Both the report and the generated margo-manifest.json have versioned output
schemas. The trees below are generated at build time from those contracts:
Margo site report v1
The JSON envelope emitted by margo site --diagnostics json.
artifactsinteger requiredNumber of published artifacts.
- Constraints
minimum=0
manifeststring requiredDigest of the exact artifact manifest.
- Constraints
pattern="^[0-9a-f]{64}$"
pagesarray requiredSource-to-output page records.
*actionsobjectmarkdownbooleanpdfbooleanpdfModestring- Constraints
enum=["pre-rendered","client"]
printChartDataboolean
alternatesarray*localestring requiredurlstring required
authorsarraycanonicalstringdescriptionstringdocumentDigeststring- Constraints
pattern="^[0-9a-f]{64}$"
familystringimageOverflowstring- Constraints
enum=["limit","allow"]
layoutstringlocalestringmodifiedAtstringoutputstring requiredSite-relative generated HTML path.
publishedAtstringsourcestring requiredSite-relative Markdown source path.
structuredDataobjectSerialized JSON-LD emitted in the page head.
tagsarraytitlestring
policystringDigest of the trusted host policy when one was supplied.
schemaVersionvalue required- Constraints
const="margo-site-report/v1"
See the site report schema reference for the full tree and its other consumers.
Margo site manifest v1
The exact publication identity emitted as margo-manifest.json.
basePathstringbaseURLstringconfigVersioninteger- Constraints
minimum=1
digeststring requiredDomain-separated digest of the artifact entries.
- Constraints
pattern="^[0-9a-f]{64}$"
documentStyleDigeststringentriesarray requiredSorted site-relative artifact paths and their exact digests.
*digeststring required- Constraints
pattern="^[0-9a-f]{64}$"
pathstring required- Constraints
minLength=1
layoutstringlayoutSchemaHashstringpolicystringDigest of the trusted host policy when one was supplied.
routesarray*actionsobjectalternatesarrayauthorsarraycanonicalstringdescriptionstringdocumentDigeststringfamilystringimageOverflowstringlayoutstringlocalestringmodifiedAtstringoutputstring requiredpublishedAtstringsourcestring requiredstructuredDataobjectSerialized JSON-LD emitted in the page head.
tagsarraytitlestring
schemaVersionvalue required- Constraints
const="margo-site-manifest/v1"
See the site manifest schema reference for the full tree and its other consumers.
Config mode takes source, output, assets, site identity, base URL or path,
layout, navigation, locale, theme, and publication settings from the config.
Without --output-dir, configured output is resolved beside that file. An
explicit --output-dir changes only the publication destination.
Minimal configured site
margo schema site emits the version-matched
JSON Schema for the top-level site.yaml shape; margo schema policy
and margo schema document emit the other
two editor contracts. A site config is a versioned, closed YAML contract
with version: 1. The generated site configuration reference
lists the v1 fields; runtime validation is implemented by the
site.Config type
in the current release line;
the repository's showcase.yaml
is a complete, larger example.
The following is a complete minimal documentation site. It expects one
Markdown source at docs/index.md, a local SVG at assets/logo.svg (the same
file can be used for icon), and a local JPEG or PNG at
assets/social.jpg. The social image must be exactly 1280×640; Margo validates
that dimension, format, and the non-empty alt text before publication.
version: 1
source: docs
output: dist
assets: local
offline: true
base_path: /docs
site:
name: Example Docs
description: A small configured documentation site.
base_url: https://docs.example.com
home: index.md
logo: assets/logo.svg
icon: assets/logo.svg
social_image:
path: assets/social.jpg
alt: Example Docs preview
layout:
kind: docs
default:
families: [default]
sidebar: true
toc: true
content:
layout: article
values:
family: default
locales:
default: en
supported: [en]
navigation:
mode: file-tree
theme:
builtin: true
name: modern
allow_switch_theme: false
color_mode: light
Create docs/index.md, put the local assets in the paths above, and build a
fresh destination:
mkdir -p docs assets build
cat > docs/index.md <<'MARKDOWN'
---
title: Example Docs
description: A small configured documentation site.
language: en
---
# Example Docs
This page is generated by the configured site contract.
MARKDOWN
margo site ./site.yaml --diagnostics json > build/site-report.json
Before committing a config, capture the exact schema for the installed binary
and attach it to site.yaml in your YAML language server:
mkdir -p .schemas
margo schema site > .schemas/margo-site.schema.json
The schema gives editor completion and local type checks. The build remains the authority for source existence, image dimensions, cross-page links, family resolution, and whether a declared theme asset is present.
The command writes dist/index.html, dist/sitemap.xml,
dist/llms.txt, and dist/margo-manifest.json; the report is
margo-site-report/v1. base_path: /docs affects public URLs and canonical
metadata, while output: dist remains a filesystem path beside site.yaml.
Set base_path: / for a root deployment. theme.name: modern selects the
built-in modern theme; allow_switch_theme and color_mode control its
runtime controls and color family. The accepted theme.builtin boolean is
shown in the example for the v1 config shape but is not a theme selector by
itself. A custom theme instead adds a themes entry with a local css_url
and token_catalog, then selects that name. navigation.mode is currently
file-tree; locales must include the default locale in its supported list.
layout.kind: docs owns search, sidebar, table of contents, pagination, and
family navigation. Archive, tag, RSS, and Atom generation remain
consumer-owned.
Create a custom site theme
Site themes are extensible; deck themes are not. A site theme is a CSS file plus
a margo.theme.tokens/v1 YAML (or JSON) sidecar. The sidecar is deliberately
larger than a color palette so every responsive and accessible projection has a
bounded value. The complete catalog template contains these top-level sections:
schema, css_digest, fonts, minimum_text_size, touch_target,
typography (display, headline, title, body, label, and caption),
reading_measure, layout, spacing, breakpoints, grid, drawer,
colors, mermaid, states, feedback, and contrast_pairs. Margo requires
the schema, digest, semantic layout/color sections, and all six typography roles;
the remaining sections are kept in the catalog so theme consumers have one
stable vocabulary.
The repository's Margo token catalog is a complete template. Starting from it avoids accidentally omitting a required semantic role:
mkdir -p themes build
# From a Margo checkout, use the files already under themes/. Otherwise fetch
# the same pinned template from the repository before editing it.
test -f themes/margo.css || curl -fsSL https://raw.githubusercontent.com/araihu/margo/v0.0.17/themes/margo.css -o themes/margo.css
test -f themes/margo.tokens.yaml || curl -fsSL https://raw.githubusercontent.com/araihu/margo/v0.0.17/themes/margo.tokens.yaml -o themes/margo.tokens.yaml
cp themes/margo.tokens.yaml themes/acme.tokens.yaml
sed 's/\[data-theme="margo"\]/[data-theme="acme"]/g' themes/margo.css > themes/acme.css
# shasum is available on macOS and most Go build environments.
digest="$(shasum -a 256 themes/acme.css | awk '{print $1}')"
awk -v digest="$digest" 'BEGIN { updated = 0 }
/^css_digest:/ { print "css_digest: sha256-" digest; updated = 1; next }
{ print }
END { if (!updated) exit 1 }' themes/acme.tokens.yaml > build/acme.tokens.yaml
mv build/acme.tokens.yaml themes/acme.tokens.yaml
Select the catalog from site.yaml and keep the paths relative to that file:
themes:
- name: acme
css_url: themes/acme.css
token_catalog: themes/acme.tokens.yaml
theme:
builtin: false
name: acme
allow_switch_theme: true
color_mode: system
css_digest is the raw SHA-256 of the exact CSS bytes with the
sha256- prefix. Margo checks the digest, required sections, typography roles,
both color modes, state/feedback entries, and contrast pairs before staging
any artifact. A missing section or stale digest reports site.theme_catalog_invalid
or site.theme_css_digest; fix the sidecar/CSS pair rather than weakening the
validator. Run margo check and then margo site with a new destination. Deck
authors instead choose only modern, goshtoso, or minimal and cannot load a
custom Marpit theme.
Page publication actions
Pages can retain their Markdown source and publish a pre-rendered PDF through frontmatter:
margo:
actions:
markdown: true
pdf: true
The PDF action also accepts an object when a branded PDF must include the exact
chart-data tables used by margo pdf --print-chart-data:
margo:
actions:
pdf:
printChartData: true
The object form defaults to pre-rendered; existing boolean and string forms
remain compatible. Use pdf: client for browser printing without publishing a
PDF artifact. See the margo pdf branding guide
for the complete branded publication workflow.
Article publication metadata
Site builds project the document metadata fields authors, publishedAt,
modifiedAt, and tags into three stable surfaces: the generated article has
an accessible publication-details header (address, labeled time elements,
and a tag list). Published and modified timestamps are shown as separate
Published/Updated values with a visible separator when both are present;
the labels wrap with their values on narrow screens and localize with the
page locale. The initial HTML head contains article:* metadata, and each
page record in the site report and margo-manifest.json carries the same fields.
This lets a blog
or news consumer build archive and tag indexes from the route records without
duplicating the values in Markdown prose.
For sources that use the common singular names, directory and configured site
builds also accept author: Name and date: YYYY-MM-DD (or an RFC 3339 value)
as aliases. The canonical names remain preferred when multiple authors or
timestamps are needed:
---
title: A calm release
language: en
authors: [Ana Silva]
publishedAt: "2026-08-25T12:00:00Z"
tags: [operations, release]
---
Margo does not generate archive, tag, RSS, or Atom pages automatically. Route records are deterministic and expose enough metadata for a consumer-owned indexer; ordering, URLs, and publication policy remain the site's responsibility.
Examples
margo site ./docs \
--output-dir ./build/site-2026-08-20 \
--assets local \
--diagnostics json > build/site-report.json
margo site ./site.yaml --diagnostics text > build/site-report.txt
Failures and diagnostics
| Code | Meaning |
|---|---|
| site.output_required | Directory mode has no --output-dir |
| site.output_exists | Destination already exists |
| site.sources_empty | No public Markdown source was found |
| site.config_invalid | YAML or closed config fields are invalid |
| site.identity_required | Configured public identity is incomplete |
| site.link_missing | A Markdown or generated link target is absent |
| site.anchor_missing | A target fragment has no matching heading |
| site.asset_external | A site image is not a local site asset |
| site.asset_outside_root | An asset escapes the source root |
| site.output_collision | Sources map to the same output path |
| site.artifact_collision | Generated artifact paths conflict |
Margo builds and validates the complete result in a sibling staging directory,
then publishes by a no-replace rename. A failure exits 1 and leaves an
existing destination untouched.
Limitations and care
Use a new versioned destination for every build; there is no --force for a
site tree. A site build is filesystem publication only. It does not deploy,
upload, tag, or release the generated directory.
Blogs and other editorial publications
Select layout.kind: docs for the native header, search and lateral TOC.
Set layout.default.sidebar: false and layout.default.pagination: false
when the publication owns its reading order. Keep toc: false as the site
default and enable layout.values.toc: true in long articles. Content-only
article pages keep their existing behavior.
Global navigation.links entries contain label and href. Destinations
are root-relative public URLs or absolute HTTPS URLs, independent of docs
families. Root-relative entries include the publication's base_path.
The native header renders them as links on desktop and a menu on smaller
screens. Do not add a second navigation bar inside Markdown.
search.label, search.placeholder and search.empty_text override the
localized search copy. site.logo_dark selects a local SVG for dark mode;
site.hide_name: true avoids repeating the name beside a wordmark while
preserving the home link's accessible name. The default logo still brands
PDF output.
The shell offsets its TOC below its responsive header and manages anchors and active sections. It shows the lateral rail at 1280px and wider, and hides it on smaller screens. No consumer header-height override is needed.