|
| 1 | +--- |
| 2 | +title: Build validation |
| 3 | +--- |
| 4 | + |
| 5 | +# Build validation |
| 6 | + |
| 7 | +Netdocs can validate your site as part of the build and report problems as **warnings**. Pair it |
| 8 | +with [`--strict`](cli.md#options) (or the `MKDOCS_STRICT` environment variable) to turn those |
| 9 | +warnings into a non-zero exit code so CI fails on a broken site. |
| 10 | + |
| 11 | +All checks are **opt-in** and default to `false`. Enable the ones you want under a `validation` |
| 12 | +block in `appsettings.json`: |
| 13 | + |
| 14 | +```json |
| 15 | +"validation": { |
| 16 | + "links": true, |
| 17 | + "anchors": true, |
| 18 | + "unusedImages": false, |
| 19 | + "orphanPages": false |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +## Checks |
| 24 | + |
| 25 | +| Option | What it checks | Emits a warning when… | |
| 26 | +|---|---|---| |
| 27 | +| `links` | Internal `href`/`src` targets in the rendered pages | a link resolves to a file that isn't in the output | |
| 28 | +| `anchors` | `#fragment` anchors on internal links (requires `links`) | the target page has no element with that `id` | |
| 29 | +| `unusedImages` | Image files under your `docs/` directory | an image is never referenced by any page | |
| 30 | +| `orphanPages` | Source Markdown pages | a page isn't reachable from the navigation tree | |
| 31 | + |
| 32 | +What is **not** flagged: |
| 33 | + |
| 34 | +- **External URLs** (`http://`, `https://`, protocol-relative `//host`), `mailto:`, `tel:`, |
| 35 | + `data:` URIs, and unresolved template tokens are skipped — link checking is offline and never |
| 36 | + makes network requests. |
| 37 | +- Generated pages (blog indexes, tag pages, etc.) are ignored by the orphan-page check. |
| 38 | + |
| 39 | +Validation runs **last**, after every page, asset, and plugin output is written, so link targets |
| 40 | +are resolved against the real files on disk. |
| 41 | + |
| 42 | +## Failing the build in CI |
| 43 | + |
| 44 | +Warnings alone don't change the exit code — they're informational. Add `--strict` to abort: |
| 45 | + |
| 46 | +```bash |
| 47 | +netdocs build --strict |
| 48 | +``` |
| 49 | + |
| 50 | +``` |
| 51 | +warn: Broken link in guide/setup.md: '../missing/' does not resolve to an output file. |
| 52 | +info: Validation found 1 problem(s). |
| 53 | +error: Aborting build: 1 warning(s) treated as errors (strict mode). |
| 54 | +``` |
| 55 | + |
| 56 | +The same applies to `netdocs deploy --strict`, which refuses to publish when validation fails. |
| 57 | +`MKDOCS_STRICT=1` is honored as an alias so existing MkDocs CI pipelines keep working. |
| 58 | + |
| 59 | +## Example: strict links in CI, lenient locally |
| 60 | + |
| 61 | +Keep the checks enabled in config, but only fail the build in CI: |
| 62 | + |
| 63 | +```json |
| 64 | +"validation": { "links": true, "anchors": true } |
| 65 | +``` |
| 66 | + |
| 67 | +```bash |
| 68 | +# Local authoring — see warnings, but keep building |
| 69 | +netdocs serve |
| 70 | + |
| 71 | +# CI — fail on any broken link or anchor |
| 72 | +netdocs build --prod --strict |
| 73 | +``` |
0 commit comments