| #!/usr/bin/env python3 | |
| """ | |
| Link Checker Script for Network Security Documentation Website | |
| Audits all internal relative links, anchors, and references inside docs/textbook. | |
| """ | |
| import os | |
| import re | |
| import sys | |
| def check_documentation_links(base_dir): | |
| broken_links = 0 | |
| total_links = 0 | |
| print(f"๐ Starting link verification in: {base_dir}") | |
| for root, _, files in os.walk(base_dir): | |
| for f in files: | |
| if f.endswith('.html'): | |
| filepath = os.path.join(root, f) | |
| rel_file = os.path.relpath(filepath, base_dir) | |
| with open(filepath, 'r', encoding='utf-8', errors='ignore') as fp: | |
| html_content = fp.read() | |
| hrefs = re.findall(r'href=[\"\']([^\"\'#]+)[\"\']', html_content) | |
| for href in hrefs: | |
| if href.startswith(('http://', 'https://', 'mailto:', 'tel:')): | |
| continue | |
| total_links += 1 | |
| target_path = os.path.normpath(os.path.join(os.path.dirname(filepath), href)) | |
| if not os.path.exists(target_path): | |
| print(f"โ Broken link in {rel_file}: '{href}' -> Target '{target_path}' does not exist.") | |
| broken_links += 1 | |
| print(f"\n๐ Summary: Audited {total_links} relative links.") | |
| if broken_links == 0: | |
| print("โ SUCCESS: All internal links are valid and target files exist!") | |
| return 0 | |
| else: | |
| print(f"โ ๏ธ FAILURE: Found {broken_links} broken links.") | |
| return 1 | |
| if __name__ == '__main__': | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| project_root = os.path.abspath(os.path.join(script_dir, '..')) | |
| target_dir = os.path.join(project_root, 'docs', 'textbook') | |
| if not os.path.exists(target_dir): | |
| print(f"Error: Target directory '{target_dir}' not found.") | |
| sys.exit(1) | |
| sys.exit(check_documentation_links(target_dir)) | |
Xet Storage Details
- Size:
- 1.98 kB
- Xet hash:
- 8498f2b9a48ba43385724185cc14d9b6654cfd5577de0506395fa4f42a464c1c
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.