Skip to content

Commit 13d9d7d

Browse files
EdwardAngertclaude
andcommitted
chore: add analyze_docs.py script for docs analysis
- Add external Python script for document structure analysis - Improves maintainability by separating Python code from YAML - Handles document heading counts and title extraction - Includes error handling for corrupted files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 69515e6 commit 13d9d7d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import json
4+
import os
5+
import re
6+
7+
files_to_analyze = sys.stdin.read().strip().split('\n')
8+
doc_structure = {}
9+
10+
for file_path in files_to_analyze:
11+
if not file_path or not file_path.endswith('.md') or not os.path.isfile(file_path):
12+
continue
13+
14+
try:
15+
with open(file_path, 'r', encoding='utf-8') as f:
16+
content = f.read()
17+
18+
# Extract title (first h1)
19+
title_match = re.search(r'^# (.+)$', content, re.MULTILINE)
20+
title = title_match.group(1) if title_match else 'Untitled'
21+
22+
# Count headings
23+
h1_count = len(re.findall(r'^# ', content, re.MULTILINE))
24+
h2_count = len(re.findall(r'^## ', content, re.MULTILINE))
25+
h3_count = len(re.findall(r'^### ', content, re.MULTILINE))
26+
27+
doc_structure[file_path] = {
28+
'title': title,
29+
'headings': {
30+
'h1': h1_count,
31+
'h2': h2_count,
32+
'h3': h3_count
33+
}
34+
}
35+
36+
print(f'Analyzed {file_path}: H1={h1_count}, H2={h2_count}, H3={h3_count}, Title="{title}"', file=sys.stderr)
37+
except Exception as e:
38+
print(f'Error analyzing {file_path}: {str(e)}', file=sys.stderr)
39+
40+
# Write JSON output
41+
with open('.github/temp/doc_structure.json', 'w', encoding='utf-8') as f:
42+
json.dump(doc_structure, f, indent=2)
43+
44+
print(json.dumps(doc_structure))

0 commit comments

Comments
 (0)