Build CLI (onto-next)

Compiles your Next.js pages into clean Markdown at build time.

What it does

Runs after next build (when wired into your package.json as next build && onto-next). It walks your compiled HTML output, runs each page through the cleaning engine (@ontosdk/core), and writes per-route .md files into public/.onto/.

Build-time, not request-time. Markdown extraction happens once per deploy — no per-request CPU cost. The middleware just streams pre-built files at runtime (plus optional context injection).

Build output

bash
$ npm run build

> next build && onto-next

[Next] Compiled successfully
[Onto] Processed 12 pages. Total size: 4.2MB → 38.1KB
[Onto] Syncing manifest with Control Plane [https://api.buildonto.dev]...
[Onto] ✓ Control Plane sync successful (12 files)

What gets extracted

ElementBehaviour
Headings (h1–h6)Preserved as Markdown headings with corrected hierarchy.
ParagraphsPlain text with whitespace normalized.
LinksMarkdown link syntax with absolute hrefs.
Lists, tablesNative Markdown equivalents.
Code blocksPreserved with language hints when detected.
JSON-LDExtracted from <script type='application/ld+json'> and preserved as a fenced block.
MetadataTitle + description + language pulled from <head>.
Tailwind / stylesStripped — no class attributes survive.
JS bundles, hydrationStripped — only the rendered HTML matters.
Tracking pixels, analyticsStripped.

Control Plane sync

When ONTO_API_KEY is set, the CLI also POSTs the manifest to /api/files on the Control Plane. Each manifest entry includes route, filename, content, html_bytes, markdown_bytes, sdkVersion. The dashboard's /serve/routes page reads from this — it's how you preview exactly what bots receive after each deploy.

If the CLI says "Control Plane sync skipped": check ONTO_API_KEY is set in your build env and ONTO_API_URL (if overridden) is reachable from the build worker. Sync failure is non-fatal — your .md files still generate; the dashboard just won't see them.