|
| 1 | +import os |
| 2 | +import re |
| 3 | + |
| 4 | +target_dir = r"c:\Users\aakan\Documents\Git\writeups\website\writeups\FinalTrace_2025" |
| 5 | + |
| 6 | +def check_titles(): |
| 7 | + files = [f for f in os.listdir(target_dir) if f.endswith('.md') and f != 'index.md'] |
| 8 | + |
| 9 | + print(f"Checking {len(files)} markdown files.") |
| 10 | + |
| 11 | + for filename in files: |
| 12 | + filepath = os.path.join(target_dir, filename) |
| 13 | + |
| 14 | + with open(filepath, 'r', encoding='utf-8') as f: |
| 15 | + content = f.read() |
| 16 | + |
| 17 | + # Extract title line |
| 18 | + match = re.search(r'^title:\s*(.*)$', content, re.MULTILINE) |
| 19 | + if match: |
| 20 | + title_value = match.group(1).strip() |
| 21 | + |
| 22 | + # Check if title starts with - or contains : without quotes |
| 23 | + if title_value.startswith('-') or (':' in title_value and not (title_value.startswith('"') or title_value.startswith("'"))): |
| 24 | + print(f"Potential issue in {filename}: title: {title_value}") |
| 25 | + |
| 26 | + # Fix it by quoting |
| 27 | + # Also if it starts with - **Category**, maybe we can find a better title? |
| 28 | + # For now, let's just quote it to fix the build error. |
| 29 | + # But for 28--category-forensics.md, the title is garbage. |
| 30 | + |
| 31 | + if filename == '28--category-forensics.md': |
| 32 | + new_title = '"Phantom User Forensics"' |
| 33 | + else: |
| 34 | + # Escape quotes if needed |
| 35 | + safe_title = title_value.replace('"', '\\"') |
| 36 | + new_title = f'"{safe_title}"' |
| 37 | + |
| 38 | + new_content = content.replace(f'title: {title_value}', f'title: {new_title}') |
| 39 | + |
| 40 | + with open(filepath, 'w', encoding='utf-8') as f: |
| 41 | + f.write(new_content) |
| 42 | + print(f"Fixed {filename} -> title: {new_title}") |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + check_titles() |
0 commit comments