Classes
LinkValidator
Validates links in pages to catch broken links.
This validator checks that internal links resolve …
LinkValidator
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.
validate_page_links
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 of broken link URLslist[str]
—
validate_site
Validate all links in the entire site.
validate_site
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 of (page_path, broken_link) tupleslist[tuple[Path | None, str]]
—
Internal Methods 3
__init__
Initialize the link validator.
__init__
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…
_build_page_url_index
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 of all valid page URLsset[str]
—
_is_valid_link
Check if a link is valid.
Validates internal links by:
1. Resolving relative p…
_is_valid_link
def _is_valid_link(self, link: str, page: Page) -> bool
Check if a link is valid.
Validates internal links by:
- Resolving relative paths against page URL
- Checking if target exists in page URL index
- Handling fragment-only links
Parameters 2
link |
str |
Link URL to check |
page |
Page |
Page containing the link |
Returns
True if link is valid, False otherwisebool
—