Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/.cache/
/.vscode/
/.idea/
__pycache__
/build/
69 changes: 69 additions & 0 deletions hooks/airspace_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import re
import logging
import csv

log = logging.getLogger("airspace_validation")

errors = []

config_state = {
'doValidation': True,
'errorOnValidationFail': True
}

class Cache:
waypoints = set()
sidstars = set()

def on_config(config):
config_state['errorOnValidationFail'] = config.get('extra', {}).get('error_on_validation_fail', True)

try:
with open('build/ap_aids.txt', newline='') as f:
reader = csv.reader(f, delimiter='\t')
for row in reader:
if row[4] in ('IFR_FIX', 'VOR', 'NDB'):
Cache.waypoints.add(row[1])

with open('build/procedures.txt', newline='') as f:
reader = csv.reader(f, delimiter='\t')
for row in reader:
if row[4] in ('STAR', 'SID'):
Cache.sidstars.add(f"{row[3]} {row[7]}".strip())
except FileNotFoundError:
print("Data not found - skipping validation")
config_state['doValidation'] = False


def on_page_markdown(markdown, page, **kwargs):
if config_state['doValidation'] == False:
return

if page.file.src_path.startswith("contribute/") or page.file.src_path.startswith("changelog"):
return

sidstarpattern = r"[A-Z]{5}\s#[A-Z]"
waypointpattern = r"`([A-Z]{5})`"

matches = re.findall(sidstarpattern, markdown)

for match in matches:
sidstarwaypoint = match[:5]
sidstaralpha = match[-1]
if not f"{sidstarwaypoint} {sidstaralpha}" in Cache.sidstars:
errors.append(f"{page.file.src_path}: SID/STAR {match} found but not valid")

matches = re.findall(waypointpattern, markdown)

for match in matches:
if not match in Cache.waypoints:
errors.append(f"{page.file.src_path}: Waypoint {match} found but not valid")

def on_post_build(config):
if errors:
log.warning("Validation issues found:")
for e in errors:
log.warning(f" - {e}")

if config_state['errorOnValidationFail']:
raise SystemExit("Validation errors occurred - not continuing")
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
python = "3.11"
11 changes: 7 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ plugins:
height: auto
zoomable: true
draggable: false


# Build hooks
hooks:
- hooks/airspace_validation.py

# Styling Front-end
extra_css:
Expand All @@ -62,9 +65,6 @@ extra_css:
- stylesheets/navigation.css
- stylesheets/custom-toc.css

toc:
- toc_class: custom-toc

# Extra Functions / Customizations
extra:
social:
Expand All @@ -80,6 +80,9 @@ extra:
analytics:
provider: google
property: G-TH1T6E4KK6
# Uncomment to bypass validation checks
# error_on_validation_fail: false

# google analytics tag to be rotated during airac cycle workflow

# Additional Markdown Extensions to use bundled icon sets
Expand Down