CLI & API#
independoc can be invoked either from the command line or programmatically as a Node.js ESM module.
CLI Commands#
bash
independoc <command> [options]| Command | Description |
|---|---|
build | Generate static site (HTML / CSS / JS / search index / sitemap.xml / llms.txt / 404.html) |
serve | Start local preview server with file watching and SSE live reload |
check | Validate Markdown, duplicate routes, internal links, anchors, and nav without writing files |
init [dir] | Scaffold a minimal independoc.config.json and starter docs/ directory |
version <name> | Snapshot the current docsDir into versioned_docs/<name>/ |
Common Options#
| Option | Default | Description |
|---|---|---|
-c, --config <path> | independoc.config.json | Path to config file |
-d, --docs <dir> | docs | Source Markdown directory |
-o, --out <dir> | dist | Output directory |
-b, --base <path> | / | Base URL path for sub-path deployment (e.g. /independoc/) |
--site-url <url> | config value | Absolute site origin used for canonical, sitemap, and llms URLs |
-p, --port <number> | 3000 | Dev server port |
--host <address> | 127.0.0.1 | Dev server bind host (supports IPv6 such as ::1) |
--include-drafts | false | Include pages marked draft: true |
--strict-links | false | Fail the build on broken links or anchors |
-v, --version | — | Print version |
-h, --help | — | Show help |
Programmatic API (ESM)#
Invoke independoc directly from custom build scripts or CI tasks.
scripts/build-docs.mjs
import { buildSite, startDevServer, renderMarkdown } from 'independoc';
// 1. Static build
const result = await buildSite({
cwd: process.cwd(),
overrides: {
basePath: '/independoc/',
onBrokenLinks: 'error',
},
});
console.log(`${result.pageCount} pages built in ${result.durationMs}ms`);
// 2. Standalone Markdown rendering
const { html, headings, customElements } = renderMarkdown('# Hello\n\n<nd-badge>Zero Dep</nd-badge>');
console.log({ headings, customElements, htmlLength: html.length });Exported Functions#
buildSite(options)— Generate static site (write: falseruns validation only)startDevServer(options)— Start dev server (returns{ server, url, port, close })loadConfig(options)/normalizeBasePath(raw)/withBasePath(href, basePath)— Config and URL helpersparseFrontmatter(source)— Frontmatter parserrenderMarkdown(markdown, options)/sanitizeUrl(url)/slugify(text)/parseLineRanges(raw)— Markdown renderinghighlightCode(code, lang)/highlightCodeLines(code, lang)— Build-time syntax highlightingdiscoverDocs(docsDirAbs, options)— Document discovery and sidebar generationbuildSearchIndex(pages, options)/htmlToPlainText(html)— Search index buildercheckLinks(params)/createLinkResolver(params)— Internal link and anchor checkernormalizeI18nConfig(config)/normalizeVersionsConfig(config)/createBuildContexts(config)— i18n and versioning context helpersbuildSitemapXml(pages, config)/buildLlmsTxt(contextResults, config)/buildLlmsFullTxt(contextResults, config)— SEO and LLM outputs
Version Snapshot CLI#
bash
independoc version v1Recursively copies the current docsDir into versioned_docs/<name>/ and prints an example JSON snippet to register the version in independoc.config.json. Existing snapshot directories and unsafe names (such as ../foo) are rejected without overwriting existing files.