process_ts_files.py•1.19 kB
#!/usr/bin/env python3
import os
import sys
def process_ts_files(folder_path):
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.ts.md'):
file_path = os.path.join(root, file)
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
if lines:
# Find first line starting with '#'
for i, line in enumerate(lines):
if line.startswith('#'):
# Insert 'typescript' after '#'
lines[i] = line.replace('#', '#typescript', 1)
break
# Replace all '/' with ' ' in all lines
lines = [line.replace('/', ' ') for line in lines]
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
print(f"Processed: {file_path}")
if __name__ == "__main__":
folder = "path/to/docs"
process_ts_files(folder)