Skip to content
Margo dev

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.

  • artifacts integer required

    Number of published artifacts.

    Constraints
    minimum=0
  • manifest string required

    Digest of the exact artifact manifest.

    Constraints
    pattern="^[0-9a-f]{64}$"
  • pages array required

    Source-to-output page records.

    • *
      • actions object
        • markdown boolean
        • pdf boolean
        • pdfMode string
          Constraints
          enum=["pre-rendered","client"]
        • printChartData boolean
      • alternates array
        • *
          • locale string required
          • url string required
      • authors array
      • canonical string
      • description string
      • documentDigest string
        Constraints
        pattern="^[0-9a-f]{64}$"
      • family string
      • imageOverflow string
        Constraints
        enum=["limit","allow"]
      • layout string
      • locale string
      • modifiedAt string
      • output string required

        Site-relative generated HTML path.

      • publishedAt string
      • source string required

        Site-relative Markdown source path.

      • structuredData object

        Serialized JSON-LD emitted in the page head.

      • tags array
      • title string
  • policy string

    Digest of the trusted host policy when one was supplied.

  • schemaVersion value 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.

  • basePath string
  • baseURL string
  • configVersion integer
    Constraints
    minimum=1
  • digest string required

    Domain-separated digest of the artifact entries.

    Constraints
    pattern="^[0-9a-f]{64}$"
  • documentStyleDigest string
  • entries array required

    Sorted site-relative artifact paths and their exact digests.

    • *
      • digest string required
        Constraints
        pattern="^[0-9a-f]{64}$"
      • path string required
        Constraints
        minLength=1
  • layout string
  • layoutSchemaHash string
  • policy string

    Digest of the trusted host policy when one was supplied.

  • routes array
    • *
      • actions object
      • alternates array
      • authors array
      • canonical string
      • description string
      • documentDigest string
      • family string
      • imageOverflow string
      • layout string
      • locale string
      • modifiedAt string
      • output string required
      • publishedAt string
      • source string required
      • structuredData object

        Serialized JSON-LD emitted in the page head.

      • tags array
      • title string
  • schemaVersion value 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.

yaml
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:

sh
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:

sh
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:

sh
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:

yaml
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:

yaml
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:

yaml
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:

markdown
---
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

sh
margo site ./docs \
  --output-dir ./build/site-2026-08-20 \
  --assets local \
  --diagnostics json > build/site-report.json
sh
margo site ./site.yaml --diagnostics text > build/site-report.txt

Failures and diagnostics

Markdown table
CodeMeaning
site.output_requiredDirectory mode has no --output-dir
site.output_existsDestination already exists
site.sources_emptyNo public Markdown source was found
site.config_invalidYAML or closed config fields are invalid
site.identity_requiredConfigured public identity is incomplete
site.link_missingA Markdown or generated link target is absent
site.anchor_missingA target fragment has no matching heading
site.asset_externalA site image is not a local site asset
site.asset_outside_rootAn asset escapes the source root
site.output_collisionSources map to the same output path
site.artifact_collisionGenerated 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.