Skip to main content

Link Suite

Verify that internal documentation links and anchors resolve to real targets with registerLinkSuite.

Summary

  • Scans content directories for internal Markdown links and the anchors they point to.
  • Resolves each link against the docs and blog route conventions, including index and frontmatter-id aliases.
  • Skips external URLs and links inside code fences so only real internal targets are checked.

Why Use This Suite?

  1. Catches broken internal links during the test run, before a strict build fails on them.
  2. Validates heading anchors so a renamed section never leaves a dangling deep link.
  3. Understands Docusaurus routing — index pages, frontmatter-id aliases, and blog routes — so valid links pass and only genuinely broken ones fail.

Examples

Usage

src/tests/link.test.ts
ts
import { registerLinkSuite } from '@cbnventures/nova/rules/vitest';
import * as vitest from 'vitest';

registerLinkSuite({
  vitest,
  enable: 'all',
});

The defaults match a standard Docusaurus layout with docs and blog directories. A docs-only site can drop the blog by omitting contentDirs.blog.

Configuration

FieldTypeDefaultDescription
projectRootstringprocess.cwd()Consumer root containing the content directories.
contentDirs{ docs: string; blog?: string }{ docs: 'docs', blog: 'blog' }Content directories to scan and how they map to route prefixes.
docsRouteBasePathstring'docs'URL route prefix for docs links.
blogRouteBasePathstring'blog'URL route prefix for blog links.
categoryRouteSkipPrefixstring'category/'Auto-generated category route prefix to skip during target validation.
fileExtensionsstring[]['.md', '.mdx']Extensions that count as Markdown content.
enable'all' | ToggleKey[]requiredWhich checks run. Use 'all' for every check, or a list to freeze a set.

Toggle Keys

Toggle KeyDescription
link-internal-doc-target-existsRequires an internal docs link to resolve to a real docs page.
link-internal-doc-anchor-existsRequires a docs link anchor to match a heading on the target page.
link-internal-blog-target-existsRequires an internal blog link to resolve to a real blog post.
link-internal-blog-anchor-existsRequires a blog link anchor to match a heading on the target post.
link-self-anchor-existsRequires a same-page anchor to match a heading in the current file.
link-skip-external-and-code-blocksExcludes external URLs and code-fence content from link validation.

Troubleshooting

  • External links are flagged — Confirm link-skip-external-and-code-blocks is enabled. It is the shared filter every other check depends on.
  • A blog-less site fails on blog checks — Omit contentDirs.blog so the blog checks have nothing to scan.
  • Anchors fail after a heading rename — Update the link anchor to match the new heading slug, which follows Docusaurus heading-id rules.