Skip to content

Commit b7c6b67

Browse files
committed
feat(docs): add menu entries check actions workflow
1 parent f472db3 commit b7c6b67

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run Python Script
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
run-script:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.12'
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
23+
- name: Run Python script
24+
run: |
25+
python bin/check-missing-menu-entries.py

bin/check-missing-menu-entries.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
import json
3+
4+
PAGES_DIR = "pages"
5+
NAV_FILE = "menu/navigation.json"
6+
7+
def get_mdx_files(root):
8+
mdx_files = []
9+
for dirpath, _, filenames in os.walk(root):
10+
for filename in filenames:
11+
if filename.endswith(".mdx"):
12+
full_path = os.path.join(dirpath, filename)
13+
rel_path = os.path.relpath(full_path, root)
14+
# Exclude index.mdx and troubleshooting
15+
if filename == "index.mdx":
16+
continue
17+
if "/troubleshooting/" in rel_path.replace("\\", "/"):
18+
continue
19+
# Exclude files directly in the pages folder
20+
if os.path.dirname(rel_path) == "":
21+
continue
22+
mdx_files.append(rel_path)
23+
return mdx_files
24+
25+
def get_slugs_from_nav(nav_json):
26+
slugs = set()
27+
def extract(obj):
28+
if isinstance(obj, dict):
29+
if "slug" in obj:
30+
slugs.add(obj["slug"])
31+
for v in obj.values():
32+
extract(v)
33+
elif isinstance(obj, list):
34+
for item in obj:
35+
extract(item)
36+
extract(nav_json)
37+
return slugs
38+
39+
def main():
40+
# Load navigation.json
41+
with open(NAV_FILE, "r", encoding="utf-8") as f:
42+
nav_json = json.load(f)
43+
nav_slugs = get_slugs_from_nav(nav_json)
44+
45+
# Get all relevant mdx files
46+
mdx_files = get_mdx_files(PAGES_DIR)
47+
48+
# Check which files are missing from navigation
49+
missing = []
50+
nav_slug_filenames = set()
51+
for slug in nav_slugs:
52+
# Extract the last part of the slug (filename without extension)
53+
slug_filename = slug.split('/')[-1].split('?')[0].split('#')[0]
54+
slug_filename = os.path.splitext(slug_filename)[0]
55+
nav_slug_filenames.add(slug_filename)
56+
57+
for mdx in mdx_files:
58+
filename = os.path.splitext(os.path.basename(mdx))[0]
59+
if filename not in nav_slug_filenames:
60+
missing.append(mdx)
61+
62+
print("MDX files missing from navigation.json:\n")
63+
for m in missing:
64+
file_path = os.path.join(PAGES_DIR, m)
65+
try:
66+
with open(file_path, "r", encoding="utf-8") as f:
67+
content = f.read()
68+
if "noindex: true" in content:
69+
print(f"{m} [noindex: true]")
70+
else:
71+
print(m)
72+
except Exception as e:
73+
print(f"{m} [error reading file: {e}]")
74+
75+
if __name__ == "__main__":
76+
main()

0 commit comments

Comments
 (0)