Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 0 additions & 261 deletions overrides/base.html

This file was deleted.

7 changes: 6 additions & 1 deletion overrides/main.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
{# Tab icons are wired in overrides/base.html (site_meta block). #}
{% extends "base.html" %}

{% block site_meta %}
{{ super() }}
<link rel="icon" href="{{ 'images/favicon.svg' | url }}" sizes="any" type="image/svg+xml">
<link rel="apple-touch-icon" href="{{ 'images/apple-touch-icon.png' | url }}">
{% endblock %}
28 changes: 20 additions & 8 deletions scripts/check_html_links.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
#!/usr/bin/env python3
"""Verify that MkDocs-built HTML pages link only to existing locations
"""Verify that MkDocs-built HTML pages reference only existing locations
in the rendered site.

The landing page (docs/index.md → site/index.html) embeds raw HTML with
href attributes. MkDocs strict mode does not validate those links, so this
script walks each href and confirms the target resolves under site/.
links and media references. MkDocs strict mode does not validate those
targets, so this script walks each href/src and confirms the target resolves
under site/.

Usage: python scripts/check_html_links.py [SITE_DIR]
(default SITE_DIR is ./site, the output of `mkdocs build`)
"""

from __future__ import annotations

import re
import sys
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import urldefrag, urlparse

HTML_PAGES = ("index.html",)
HREF_RE = re.compile(r'href="([^"]+)"')
TARGET_ATTRS = {"href", "src"}


class TargetParser(HTMLParser):
def __init__(self) -> None:
super().__init__()
self.targets: list[str] = []

def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
for name, value in attrs:
if name in TARGET_ATTRS and value:
self.targets.append(value)


def is_external(href: str) -> bool:
Expand Down Expand Up @@ -58,9 +70,9 @@ def main() -> int:
if not path.exists():
errors.append(f"{page}: not present in {site}")
continue
content = path.read_text(encoding="utf-8")
for match in HREF_RE.finditer(content):
href = match.group(1)
parser = TargetParser()
parser.feed(path.read_text(encoding="utf-8"))
for href in parser.targets:
if is_external(href):
continue
ok, msg = resolve(path.parent, site, href)
Expand Down
Loading