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