#!/usr/bin/env bash # # migrate_content.sh # # Migrates content from the old jon.recoil.org-src site to the mono repo's # site/ directory. Copies .mld files, static assets, and applies format # transformations for the new odoc-based build system. # # Usage: ./scripts/migrate_content.sh # Run from the mono repo root. set -euo pipefail # Resolve paths SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MONO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" OLD_SITE="/home/jons-agent/workspace/jon.recoil.org-src" NEW_SITE="$MONO_ROOT/site" if [ ! -d "$OLD_SITE" ]; then echo "ERROR: Old site directory not found at $OLD_SITE" exit 1 fi echo "=== Content Migration Script ===" echo " Source: $OLD_SITE" echo " Destination: $NEW_SITE" echo "" # Track files needing manual review REVIEW_FILES_OCAMLTOP=() REVIEW_FILES_DEFERRED=() REVIEW_FILES_PROMPT=() # ============================================================ # Step 1: Copy content directories # ============================================================ echo "--- Step 1: Copying content ---" # 1a. Copy blog .mld files, preserving directory structure echo " Copying blog/ ..." if [ -d "$OLD_SITE/blog" ]; then find "$OLD_SITE/blog" -name "*.mld" -type f | while read -r src; do rel="${src#$OLD_SITE/}" dest="$NEW_SITE/$rel" mkdir -p "$(dirname "$dest")" cp "$src" "$dest" done blog_count=$(find "$NEW_SITE/blog" -name "*.mld" -type f | wc -l) echo " Copied $blog_count .mld files" else echo " WARNING: $OLD_SITE/blog does not exist" fi # 1b. Copy notebooks .mld files, preserving directory structure echo " Copying notebooks/ ..." if [ -d "$OLD_SITE/notebooks" ]; then find "$OLD_SITE/notebooks" -name "*.mld" -type f | while read -r src; do rel="${src#$OLD_SITE/}" dest="$NEW_SITE/$rel" mkdir -p "$(dirname "$dest")" cp "$src" "$dest" done nb_count=$(find "$NEW_SITE/notebooks" -name "*.mld" -type f | wc -l) echo " Copied $nb_count .mld files" else echo " WARNING: $OLD_SITE/notebooks does not exist" fi # 1c. Copy static assets echo " Copying static/ ..." if [ -d "$OLD_SITE/static" ]; then cp -r "$OLD_SITE/static/." "$NEW_SITE/static/" static_count=$(find "$NEW_SITE/static" -type f | wc -l) echo " Copied $static_count static files" else echo " WARNING: $OLD_SITE/static does not exist" fi # 1d. Copy notes/ if it exists echo " Copying notes/ ..." if [ -d "$OLD_SITE/notes" ] && [ -n "$(ls -A "$OLD_SITE/notes" 2>/dev/null)" ]; then mkdir -p "$NEW_SITE/notes" find "$OLD_SITE/notes" -name "*.mld" -type f | while read -r src; do rel="${src#$OLD_SITE/}" dest="$NEW_SITE/$rel" mkdir -p "$(dirname "$dest")" cp "$src" "$dest" done notes_count=$(find "$NEW_SITE/notes" -name "*.mld" -type f 2>/dev/null | wc -l) echo " Copied $notes_count .mld files" else echo " Skipped (directory empty or does not exist)" fi # 1e. Copy drafts/ if it exists echo " Copying drafts/ ..." if [ -d "$OLD_SITE/drafts" ] && [ -n "$(ls -A "$OLD_SITE/drafts" 2>/dev/null)" ]; then mkdir -p "$NEW_SITE/drafts" find "$OLD_SITE/drafts" -name "*.mld" -type f | while read -r src; do rel="${src#$OLD_SITE/}" dest="$NEW_SITE/$rel" mkdir -p "$(dirname "$dest")" cp "$src" "$dest" done drafts_count=$(find "$NEW_SITE/drafts" -name "*.mld" -type f 2>/dev/null | wc -l) echo " Copied $drafts_count .mld files" else echo " Skipped (directory empty or does not exist)" fi # 1f. Copy reference/ .mld files only (not build output) echo " Copying reference/ ..." if [ -d "$OLD_SITE/reference" ]; then mkdir -p "$NEW_SITE/reference" find "$OLD_SITE/reference" -name "*.mld" -type f | while read -r src; do rel="${src#$OLD_SITE/}" dest="$NEW_SITE/$rel" mkdir -p "$(dirname "$dest")" cp "$src" "$dest" done ref_count=$(find "$NEW_SITE/reference" -name "*.mld" -type f 2>/dev/null | wc -l) echo " Copied $ref_count .mld files" else echo " Skipped (directory does not exist)" fi echo "" # ============================================================ # Step 2: Apply transformations to all .mld files # ============================================================ echo "--- Step 2: Applying transformations ---" transform_count=0 libs_count=0 switch_count=0 notanotebook_count=0 autorun_count=0 ocamltop_plain_count=0 find "$NEW_SITE" -name "*.mld" -type f | sort | while read -r file; do modified=false # 2a. Replace {@ocamltop autorun[ with {@ocaml run-on=load[ # This handles variants like: {@ocamltop autorun hidden[ if grep -q '{@ocamltop autorun' "$file" 2>/dev/null; then # Replace {@ocamltop autorun[ with {@ocaml run-on=load[ # Also handle {@ocamltop autorun hidden[ -> {@ocaml run-on=load hidden[ sed -i 's/{@ocamltop autorun\b/{@ocaml run-on=load/g' "$file" modified=true autorun_count=$((autorun_count + 1)) fi # Also handle {x@ocamltop autorun[ -> {x@ocaml run-on=load[ if grep -q '{x@ocamltop autorun' "$file" 2>/dev/null; then sed -i 's/{x@ocamltop autorun\b/{x@ocaml run-on=load/g' "$file" modified=true fi # Also handle {@ocaml autorun -> {@ocaml run-on=load (non-ocamltop variant) if grep -q '{@ocaml autorun' "$file" 2>/dev/null; then sed -i 's/{@ocaml autorun\b/{@ocaml run-on=load/g' "$file" modified=true fi # 2b. Replace {@ocamltop skip[ with {@ocaml skip[ if grep -q '{@ocamltop skip' "$file" 2>/dev/null; then sed -i 's/{@ocamltop skip\b/{@ocaml skip/g' "$file" modified=true fi # 2c. Replace remaining {@ocamltop[ with {@ocaml[ if grep -q '{@ocamltop\[' "$file" 2>/dev/null; then sed -i 's/{@ocamltop\[/{@ocaml[/g' "$file" modified=true ocamltop_plain_count=$((ocamltop_plain_count + 1)) fi # Also handle {x@ocamltop[ -> {x@ocaml[ if grep -q '{x@ocamltop\[' "$file" 2>/dev/null; then sed -i 's/{x@ocamltop\[/{x@ocaml[/g' "$file" modified=true fi # 2d. Transform @libs lines: space-separated to comma-separated @x-ocaml.requires # e.g. @libs pkg1 pkg2 pkg3 -> @x-ocaml.requires pkg1,pkg2,pkg3 if grep -q '^@libs ' "$file" 2>/dev/null; then sed -i '/^@libs /{s/^@libs //; s/ /,/g; s/^/@x-ocaml.requires /}' "$file" modified=true libs_count=$((libs_count + 1)) fi # 2e. Remove @switch oxcaml lines entirely if grep -q '^@switch ' "$file" 2>/dev/null; then sed -i '/^@switch /d' "$file" modified=true switch_count=$((switch_count + 1)) fi # 2f. Remove @notanotebook lines entirely if grep -q '^@notanotebook' "$file" 2>/dev/null; then sed -i '/^@notanotebook$/d' "$file" modified=true notanotebook_count=$((notanotebook_count + 1)) fi if [ "$modified" = true ]; then transform_count=$((transform_count + 1)) fi done echo " Files transformed: see summary below" echo "" # ============================================================ # Step 3: Flag files for manual review # ============================================================ echo "--- Step 3: Checking for files needing manual review ---" echo "" # 3a. Check for remaining ocamltop (incomplete transformation) echo " [CHECK] Files still containing 'ocamltop' (incomplete transformation):" remaining_ocamltop=0 while IFS= read -r file; do rel="${file#$NEW_SITE/}" echo " - $rel" remaining_ocamltop=$((remaining_ocamltop + 1)) done < <(grep -rl 'ocamltop' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) if [ "$remaining_ocamltop" -eq 0 ]; then echo " (none -- all ocamltop references transformed)" fi echo "" # 3b. Check for {x@ocaml[ (deferred blocks needing manual handling) echo " [CHECK] Files containing '{x@ocaml[' (deferred blocks, need manual review):" deferred_count=0 while IFS= read -r file; do rel="${file#$NEW_SITE/}" echo " - $rel" deferred_count=$((deferred_count + 1)) done < <(grep -rl '{x@ocaml\[' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) if [ "$deferred_count" -eq 0 ]; then echo " (none)" fi echo "" # 3c. Check for lines starting with # inside code blocks (old prompt prefixes) echo " [CHECK] Files with '# ' prompt prefixes inside code blocks (need manual review):" prompt_count=0 while IFS= read -r file; do rel="${file#$NEW_SITE/}" echo " - $rel" prompt_count=$((prompt_count + 1)) done < <(grep -rl '^# ' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) if [ "$prompt_count" -eq 0 ]; then echo " (none)" fi echo "" # ============================================================ # Summary # ============================================================ echo "=== Migration Summary ===" total_mld=$(find "$NEW_SITE" -name "*.mld" -type f | wc -l) total_static=$(find "$NEW_SITE/static" -type f 2>/dev/null | wc -l) echo " Total .mld files migrated: $total_mld" echo " Total static files copied: $total_static" echo "" echo " Transformations applied:" echo " @ocamltop autorun -> @ocaml run-on=load" echo " @ocamltop[ -> @ocaml[" echo " @libs -> @x-ocaml.requires (comma-separated)" echo " @switch lines removed" echo " @notanotebook lines removed" echo "" echo " Files needing manual review: $((remaining_ocamltop + deferred_count + prompt_count))" echo " - Remaining ocamltop: $remaining_ocamltop" echo " - Deferred blocks ({x@ocaml[): $deferred_count" echo " - Prompt prefixes (# ): $prompt_count" echo "" echo "=== Done ==="