Module

rendering.link_validator

Link validation for catching broken links.

This module validates internal links in pages against the site's page URLs to catch broken links during build time.

Key features:

  • Validates internal links resolve to existing pages
  • Handles relative paths and fragments
  • Supports trailing slash variations
  • Caches validation results for performance

Classes

LinkValidator
Validates links in pages to catch broken links. This validator checks that internal links resolve …
5

Validates links in pages to catch broken links.

This validator checks that internal links resolve to existing pages in the site. External links (http/https), mailto, tel, and fragment-only links are skipped (external link checking is handled by health/validators/links.py).

Attributes

Name Type Description
validated_urls

Set of URLs that have been validated (cache)

broken_links

List of (page_path, broken_link) tuples

_page_urls

Cached set of all page URLs for O(1) lookup

_site

Reference to site being validated

Methods 2

validate_page_links
Validate all links in a page.
2 list[str]
def validate_page_links(self, page: Page, site: Any | None = None) -> list[str]

Validate all links in a page.

Parameters 2
page Page

Page to validate

site Any | None

Optional Site instance (uses cached if not provided)

Returns

list[str]

List of broken link URLs

validate_site
Validate all links in the entire site.
1 list[tuple[Path | N…
def validate_site(self, site: Any) -> list[tuple[Path | None, str]]

Validate all links in the entire site.

Parameters 1
site Any

Site instance

Returns

list[tuple[Path | None, str]]

List of (page_path, broken_link) tuples

Internal Methods 3
__init__
Initialize the link validator.
1 None
def __init__(self, site: Site | None = None) -> None

Initialize the link validator.

Parameters 1
site Site | None

Optional Site instance for URL resolution

_build_page_url_index
Build an index of all page URLs for fast lookup. Creates normalized URL varian…
1 set[str]
def _build_page_url_index(self, site: Any) -> set[str]

Build an index of all page URLs for fast lookup.

Creates normalized URL variants (with/without trailing slashes) for flexible matching.

Parameters 1
site Any

Site instance containing pages

Returns

set[str]

Set of all valid page URLs

_is_valid_link
Check if a link is valid. Validates internal links by: 1. Resolving relative p…
2 bool
def _is_valid_link(self, link: str, page: Page) -> bool

Check if a link is valid.

Validates internal links by:

  1. Resolving relative paths against page URL
  2. Checking if target exists in page URL index
  3. Handling fragment-only links
Parameters 2
link str

Link URL to check

page Page

Page containing the link

Returns

bool

True if link is valid, False otherwise