#!/bin/bash # # Script to add YAML front-matter to markdown files # DOCS_PATH="/home/isem/workspace-v1/projects/trading-platform/docs" PROCESSED=0 SKIPPED=0 add_yaml_to_file() { local file="$1" local first_line=$(head -1 "$file") # Skip if already has YAML if [ "$first_line" = "---" ]; then ((SKIPPED++)) return fi local filename=$(basename "$file") local dirname=$(dirname "$file") local parent_dir=$(basename "$dirname") local content=$(cat "$file") # Extract title from first H1 local title=$(echo "$content" | grep -m 1 "^# " | sed 's/^# //' | sed 's/:.*$//') # Extract epic from path local epic=$(echo "$file" | grep -o 'OQI-[0-9]*' | head -1) # Determine file type and create YAML local yaml="" if [[ "$filename" == RF-* ]]; then local file_id=$(echo "$filename" | sed 's/\.md$//' | grep -o '^RF-[A-Z]*-[0-9]*') yaml="--- 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 [[ "$filename" == ET-* ]]; then local file_id=$(echo "$filename" | sed 's/\.md$//' | grep -o '^ET-[A-Z]*-[0-9]*') yaml="--- 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 [[ "$filename" == US-* ]]; then local file_id=$(echo "$filename" | sed 's/\.md$//' | grep -o '^US-[A-Z]*-[0-9]*') yaml="--- 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 [[ "$filename" == "_MAP.md" ]]; then yaml="--- id: \"MAP-$parent_dir\" title: \"Mapa de $parent_dir\" type: \"Index\" project: \"trading-platform\" updated_date: \"2026-01-04\" --- " else local file_id=$(echo "$filename" | sed 's/\.md$//') yaml="--- id: \"$file_id\" title: \"$title\" type: \"Documentation\" project: \"trading-platform\" version: \"1.0.0\" updated_date: \"2026-01-04\" --- " fi # Write new content echo -n "$yaml$content" > "$file" ((PROCESSED++)) echo "PROCESSED: ${file#$DOCS_PATH/}" } # Process all markdown files find "$DOCS_PATH" -name "*.md" -type f | while read file; do add_yaml_to_file "$file" done echo "" echo "=== SUMMARY ===" echo "Processed: $PROCESSED" echo "Skipped: $SKIPPED"