workspace-v1/scripts/add_yaml_frontmatter.py
rckrdmrd cb4c0681d3 feat(workspace): Add new projects and update architecture
New projects created:
- michangarrito (marketplace mobile)
- template-saas (SaaS template)
- clinica-dental (dental ERP)
- clinica-veterinaria (veterinary ERP)

Architecture updates:
- Move catalog from core/ to shared/
- Add MCP servers structure and templates
- Add git management scripts
- Update SUBREPOSITORIOS.md with 15 new repos
- Update .gitignore for new projects

Repository infrastructure:
- 4 main repositories
- 11 subrepositorios
- Gitea remotes configured

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 04:43:28 -06:00

150 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Script to add YAML front-matter to markdown files in trading-platform/docs
"""
import os
import re
from pathlib import Path
docs_path = '/home/isem/workspace-v1/projects/trading-platform/docs'
def get_epic_from_path(path):
"""Extract epic code from path like OQI-001, OQI-002, etc."""
match = re.search(r'OQI-(\d+)', path)
if match:
return f"OQI-{match.group(1)}"
return ""
def get_title_from_content(content, filename):
"""Extract title from first H1 header or filename"""
lines = content.split('\n')
for line in lines:
if line.startswith('# '):
title = line[2:].strip()
if ':' in title:
return title.split(':', 1)[1].strip()
return title
return filename.replace('.md', '').replace('-', ' ')
def create_yaml_frontmatter(file_type, file_id, title, epic):
"""Create YAML front-matter based on file type"""
if file_type == 'RF':
return f'''---
id: "{file_id}"
title: "{title}"
type: "Requirement"
status: "Done"
priority: "Alta"
epic: "{epic}"
project: "trading-platform"
version: "1.0.0"
created_date: "2025-12-05"
updated_date: "2026-01-04"
---
'''
elif file_type == 'ET':
return f'''---
id: "{file_id}"
title: "{title}"
type: "Technical Specification"
status: "Done"
priority: "Alta"
epic: "{epic}"
project: "trading-platform"
version: "1.0.0"
created_date: "2025-12-05"
updated_date: "2026-01-04"
---
'''
elif file_type == 'US':
return f'''---
id: "{file_id}"
title: "{title}"
type: "User Story"
status: "Done"
priority: "Media"
epic: "{epic}"
project: "trading-platform"
story_points: 3
created_date: "2025-12-05"
updated_date: "2026-01-04"
---
'''
elif file_type == 'MAP':
return f'''---
id: "MAP-{file_id}"
title: "Mapa de {file_id}"
type: "Index"
project: "trading-platform"
updated_date: "2026-01-04"
---
'''
else:
return f'''---
id: "{file_id}"
title: "{title}"
type: "Documentation"
project: "trading-platform"
version: "1.0.0"
updated_date: "2026-01-04"
---
'''
def process_file(filepath):
"""Add YAML front-matter to file if missing"""
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
if content.strip().startswith('---'):
return False
filename = os.path.basename(filepath)
if filename.startswith('RF-'):
file_type = 'RF'
match = re.match(r'(RF-[A-Z]+-\d+)', filename)
file_id = match.group(1) if match else filename.replace('.md', '')
elif filename.startswith('ET-'):
file_type = 'ET'
match = re.match(r'(ET-[A-Z]+-\d+)', filename)
file_id = match.group(1) if match else filename.replace('.md', '')
elif filename.startswith('US-'):
file_type = 'US'
match = re.match(r'(US-[A-Z]+-\d+)', filename)
file_id = match.group(1) if match else filename.replace('.md', '')
elif filename == '_MAP.md':
file_type = 'MAP'
file_id = os.path.basename(os.path.dirname(filepath))
else:
file_type = 'OTHER'
file_id = filename.replace('.md', '')
epic = get_epic_from_path(filepath)
title = get_title_from_content(content, filename)
yaml_header = create_yaml_frontmatter(file_type, file_id, title, epic)
new_content = yaml_header + content
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
return True
def main():
processed = 0
skipped = 0
for root, dirs, files in os.walk(docs_path):
for filename in files:
if filename.endswith('.md'):
filepath = os.path.join(root, filename)
if process_file(filepath):
processed += 1
print(f"PROCESSED: {os.path.relpath(filepath, docs_path)}")
else:
skipped += 1
print(f"\n=== SUMMARY ===")
print(f"Processed (added YAML): {processed}")
print(f"Skipped (already had YAML): {skipped}")
print(f"Total: {processed + skipped}")
if __name__ == '__main__':
main()