Check a corpus #

View this page as Markdown

On this page

Prompt:

Check the docs for broken links and bad front matter before we publish, and fix whatever it finds.

Also works: "Run the docs check in CI." "Why did the docs build fail?"

Run tzdocs check --source docs (step 1), read each line it prints (step 2), and correct the source files the lines point to (step 3). Run the check again until it exits with code 0, then review the content and the rendered pages (step 4). You can also put the check in a pipeline ahead of the build (step 5).

What your AI tool does #

  • Runs the check against the same source folder or config file as the build, adding --include-hidden if the build includes hidden pages.
  • Reads each finding line: the source file, the finding, and, for a code block, the line and the fence.
  • Corrects the source file each line points to, without touching the generated output.
  • Runs the check again until it prints its success line, then reviews the content and the rendered pages, which the check does not cover.
  • When asked, adds the same command to the test suite, a pre-commit hook, or the deploy pipeline, ahead of the build.
  • Asks nothing: the check writes nothing, and the corrections are edits to your source files.

Before your AI starts #

Your AI coding agent checks these things before it starts.

  • The tool installed and the source folder or config file the build uses (Getting started).
  • Whether the build passes --include-hidden, so that the check covers the same pages.

Steps #

1. Run the check #

This command checks the folder docs.

tzdocs check --source docs

The check reads the Markdown source files and writes nothing. It prints each finding on its own line and exits with code 1 when there is any. For a corpus with no finding, it prints this line and exits with code 0.

check: clean — source metadata, routes, Markdown links, heading targets, and code fences passed the supported checks

For a build that uses a config file, check the same file instead:

tzdocs check --config tzdocs.json

With neither --source nor --config, tzdocs check reads tzdocs.json from the current folder. A config that names several products checks every product and prefixes each product's findings with its base path. Add --include-hidden if the build uses it.

The check validates the config file, including its source and opening paths. A flag that the config replaces cannot be given beside it; Getting started lists those flags. With --source, the check ignores build-option values. In either form, a missing flag value, a repeated flag, or an unknown flag is a usage error. Extra positional arguments are ignored.

2. Read the lines #

Each line gives the source file and what is wrong. There are two kinds of line:

  • A refusal stops the build before it writes anything, for example two files resolve to one slug /guides — guides/index.md and guides.md.
  • An advisory finding lets the build proceed, for example broken internal link in index.md — install.md#setup matches no heading anchor on install.md.

A code-block finding also gives the fence's line and quotes its info string, so you can find the fence. Code fences says which line it gives and how it quotes. Refusals and findings lists every line the check can print, with its cause and its remedy.

3. Correct the sources #

Edit the source files the lines point to. The tool never rewrites a source. Page source gives the slug and front-matter rules that a refusal reports as broken, and Highlight a code block gives the fence line.

4. Run the check again #

Exit code 0 means the checks listed in step 5 passed. It says nothing about accuracy, command coverage, readability, or accessibility, so review the content and the rendered pages after it.

5. Put the check in a pipeline #

Run the same command in a test suite, a pre-commit hook, or a deploy pipeline before the build, so that a corpus with a finding never reaches a published site. The check covers:

  • source metadata and routes;
  • internal Markdown links to pages and redirects, inline and reference links alike, with their titles, in lists, block quotes, and tables;
  • images and links to files beside the pages;
  • heading anchors;
  • code-fence metadata, including duplicate copy= keys and a title, line set, showLineNumbers or copy= on a mermaid fence;
  • callout markers, including a bracketed word that is not one of the five;
  • markdown-only section markers: a nested opening, an unmatched closing, or an unclosed section. While one stands, the check prints those lines and the source-level refusals alone, so run it again after fixing the markers.

It skips link-like text inside code. It does not fetch external URLs, and it does not read images, links, or ids written in raw HTML.

The build, not the check, validates the output folder and the shell's markers. It also checks files supplied by --shell, --home-opening, and --stylesheet; the check ignores those flag values. An opening named in a config file is different: the config reader requires that file to exist in both modes. The check neither reads nor validates its HTML.

The build can also fail during generation or publication. A link to a missing page, a reference to a missing file, or a malformed markdown-only marker stops the build as well. A missing heading, a bad fence, an unknown callout marker, or a declared section that names no top-level section does not stop the build. A pipeline that must stop on one runs the check first.

Expected result #

The check prints its success line and exits with code 0, and the build that follows prints its success line and exits with code 0. In a pipeline, a finding stops the run before the build.

Refusals #

The check rejects a wrong command line, an absent or invalid config file, or findings in the source. A missing source folder given with --source can end it with a Node.js error and exit code 1; a missing source named in a config produces a config refusal. The table below covers common cases. Refusals and findings lists the rest with their remedies.

Message Exit code Cause Remedy
a mode and --source or --config are required 2 The mode is not check or build. Or neither --source nor --config is given, and the current folder holds no tzdocs.json. Write tzdocs check --source <dir>.
--source needs a value 2 The flag is the last argument or is followed by another flag. Give the folder after the flag.
--source is given twice 2 The flag appears twice. Give it once.
--<name> is not a flag the tool knows 2 A misspelled or unknown flag. Use a flag from the table on Getting started.
the config file is absent at <path> 1 The named config file does not exist. Correct its path or create the file.
the config file <path> is invalid — <reason> 1 A config value or a source or opening path is invalid. Correct each reason the command prints.
one or more finding lines 1 The corpus has a finding. Correct the source files the lines give, and run again.