-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_ormd.py
More file actions
149 lines (120 loc) · 4.2 KB
/
update_ormd.py
File metadata and controls
149 lines (120 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
"""Update existing markdown files to use ORMD schema"""
import os
import re
from pathlib import Path
from datetime import datetime
# Files that have already been updated
ALREADY_UPDATED = {
'/workspaces/EssenceEngine/docs/INDEX.md',
'/workspaces/EssenceEngine/docs/architecture/README.md',
'/workspaces/EssenceEngine/docs/how-to/README.md',
'/workspaces/EssenceEngine/docs/architecture/TECHNICAL_DOC.md',
'/workspaces/EssenceEngine/docs/how-to/TRAINING_GUIDE.md',
'/workspaces/EssenceEngine/docs/ormd_schema.md', # Skip the schema itself
}
# Archive and TC docs - skip these
SKIP_PATTERNS = {
'/workspaces/EssenceEngine/docs/archive/',
}
def extract_title_from_filename(filename):
"""Extract title from filename"""
name = Path(filename).stem
# Convert UPPER_CASE_WITH_UNDERSCORES to Title Case
title = name.replace('_', ' ').title()
return title
def extract_title_from_content(content):
"""Extract title from first markdown heading"""
lines = content.split('\n')
for line in lines:
if line.startswith('# '):
return line[2:].strip()
return None
def generate_ormd_header(filepath, title=None):
"""Generate ORMD header with YAML front matter"""
filename = os.path.basename(filepath)
# Extract title from content or filename
if not title:
title = extract_title_from_filename(filename)
# Sanitize title (remove emojis and excessive punctuation)
title = re.sub(r'[^\w\s\-:().]', '', title).strip()
# Determine status based on filename
status = "complete"
if "TODO" in filename or "WIP" in filename:
status = "in-progress"
elif "DRAFT" in filename:
status = "draft"
timestamp = datetime.now().isoformat() + 'Z'
header = f"""<!-- ormd:0.1 -->
---
title: "{title}"
authors: ["Emergence Engine Team"]
dates:
created: '{timestamp}'
links: []
status: "{status}"
description: "Emergence Engine documentation"
---
"""
return header
def has_ormd_header(content):
"""Check if content already has ORMD header"""
return content.startswith('<!-- ormd:')
def update_file(filepath):
"""Update a single file with ORMD header"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Skip if already has ORMD header
if has_ormd_header(content):
print(f"⏭️ SKIP (already updated): {filepath}")
return False
# Extract title from first heading
title = extract_title_from_content(content)
# Generate header
header = generate_ormd_header(filepath, title)
# Combine header and content
new_content = header + '\n' + content
# Write back
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"✅ UPDATED: {filepath}")
return True
except Exception as e:
print(f"❌ ERROR: {filepath} - {str(e)}")
return False
def main():
"""Update all markdown files in docs directory"""
docs_dir = '/workspaces/EssenceEngine/docs'
updated_count = 0
skipped_count = 0
# Find all markdown files
md_files = list(Path(docs_dir).rglob('*.md'))
print(f"Found {len(md_files)} markdown files")
print("=" * 60)
for md_file in sorted(md_files):
filepath = str(md_file)
# Skip already updated files
if filepath in ALREADY_UPDATED:
print(f"⏭️ SKIP (already processed): {filepath}")
skipped_count += 1
continue
# Skip archive files
skip = False
for pattern in SKIP_PATTERNS:
if pattern in filepath:
print(f"⏭️ SKIP (archive/tc): {filepath}")
skip = True
skipped_count += 1
break
if skip:
continue
if update_file(filepath):
updated_count += 1
else:
skipped_count += 1
print("=" * 60)
print(f"✅ Updated: {updated_count} files")
print(f"⏭️ Skipped: {skipped_count} files")
if __name__ == '__main__':
main()