Skip to content
Closed
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
26 changes: 26 additions & 0 deletions .github/workflows/check-missing-menu-entries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check missing menu entries

on:
pull_request:
workflow_dispatch:

jobs:
run-script:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip

- name: Run Python script
run: |
python bin/check-missing-menu-entries.py
76 changes: 76 additions & 0 deletions bin/check-missing-menu-entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import json

PAGES_DIR = "pages"
NAV_FILE = "menu/navigation.json"

def get_mdx_files(root):
mdx_files = []
for dirpath, _, filenames in os.walk(root):
for filename in filenames:
if filename.endswith(".mdx"):
full_path = os.path.join(dirpath, filename)
rel_path = os.path.relpath(full_path, root)
# Exclude index.mdx and troubleshooting
if filename == "index.mdx":
continue
if "/troubleshooting/" in rel_path.replace("\\", "/"):
continue
# Exclude files directly in the pages folder
if os.path.dirname(rel_path) == "":
continue
mdx_files.append(rel_path)
return mdx_files

def get_slugs_from_nav(nav_json):
slugs = set()
def extract(obj):
if isinstance(obj, dict):
if "slug" in obj:
slugs.add(obj["slug"])
for v in obj.values():
extract(v)
elif isinstance(obj, list):
for item in obj:
extract(item)
extract(nav_json)
return slugs

def main():
# Load navigation.json
with open(NAV_FILE, "r", encoding="utf-8") as f:
nav_json = json.load(f)
nav_slugs = get_slugs_from_nav(nav_json)

# Get all relevant mdx files
mdx_files = get_mdx_files(PAGES_DIR)

# Check which files are missing from navigation
missing = []
nav_slug_filenames = set()
for slug in nav_slugs:
# Extract the last part of the slug (filename without extension)
slug_filename = slug.split('/')[-1].split('?')[0].split('#')[0]
slug_filename = os.path.splitext(slug_filename)[0]
nav_slug_filenames.add(slug_filename)

for mdx in mdx_files:
filename = os.path.splitext(os.path.basename(mdx))[0]
if filename not in nav_slug_filenames:
missing.append(mdx)

print("MDX files missing from navigation.json:\n")
for m in missing:
file_path = os.path.join(PAGES_DIR, m)
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
if "noindex: true" in content:
print(f"{m} [noindex: true]")
else:
print(m)
except Exception as e:
print(f"{m} [error reading file: {e}]")

if __name__ == "__main__":
main()
Loading