My aggregated monorepo of OCaml code, automaintained
at main 286 lines 9.3 kB view raw
1#!/usr/bin/env bash 2# 3# migrate_content.sh 4# 5# Migrates content from the old jon.recoil.org-src site to the mono repo's 6# site/ directory. Copies .mld files, static assets, and applies format 7# transformations for the new odoc-based build system. 8# 9# Usage: ./scripts/migrate_content.sh 10# Run from the mono repo root. 11 12set -euo pipefail 13 14# Resolve paths 15SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 16MONO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" 17OLD_SITE="/home/jons-agent/workspace/jon.recoil.org-src" 18NEW_SITE="$MONO_ROOT/site" 19 20if [ ! -d "$OLD_SITE" ]; then 21 echo "ERROR: Old site directory not found at $OLD_SITE" 22 exit 1 23fi 24 25echo "=== Content Migration Script ===" 26echo " Source: $OLD_SITE" 27echo " Destination: $NEW_SITE" 28echo "" 29 30# Track files needing manual review 31REVIEW_FILES_OCAMLTOP=() 32REVIEW_FILES_DEFERRED=() 33REVIEW_FILES_PROMPT=() 34 35# ============================================================ 36# Step 1: Copy content directories 37# ============================================================ 38 39echo "--- Step 1: Copying content ---" 40 41# 1a. Copy blog .mld files, preserving directory structure 42echo " Copying blog/ ..." 43if [ -d "$OLD_SITE/blog" ]; then 44 find "$OLD_SITE/blog" -name "*.mld" -type f | while read -r src; do 45 rel="${src#$OLD_SITE/}" 46 dest="$NEW_SITE/$rel" 47 mkdir -p "$(dirname "$dest")" 48 cp "$src" "$dest" 49 done 50 blog_count=$(find "$NEW_SITE/blog" -name "*.mld" -type f | wc -l) 51 echo " Copied $blog_count .mld files" 52else 53 echo " WARNING: $OLD_SITE/blog does not exist" 54fi 55 56# 1b. Copy notebooks .mld files, preserving directory structure 57echo " Copying notebooks/ ..." 58if [ -d "$OLD_SITE/notebooks" ]; then 59 find "$OLD_SITE/notebooks" -name "*.mld" -type f | while read -r src; do 60 rel="${src#$OLD_SITE/}" 61 dest="$NEW_SITE/$rel" 62 mkdir -p "$(dirname "$dest")" 63 cp "$src" "$dest" 64 done 65 nb_count=$(find "$NEW_SITE/notebooks" -name "*.mld" -type f | wc -l) 66 echo " Copied $nb_count .mld files" 67else 68 echo " WARNING: $OLD_SITE/notebooks does not exist" 69fi 70 71# 1c. Copy static assets 72echo " Copying static/ ..." 73if [ -d "$OLD_SITE/static" ]; then 74 cp -r "$OLD_SITE/static/." "$NEW_SITE/static/" 75 static_count=$(find "$NEW_SITE/static" -type f | wc -l) 76 echo " Copied $static_count static files" 77else 78 echo " WARNING: $OLD_SITE/static does not exist" 79fi 80 81# 1d. Copy notes/ if it exists 82echo " Copying notes/ ..." 83if [ -d "$OLD_SITE/notes" ] && [ -n "$(ls -A "$OLD_SITE/notes" 2>/dev/null)" ]; then 84 mkdir -p "$NEW_SITE/notes" 85 find "$OLD_SITE/notes" -name "*.mld" -type f | while read -r src; do 86 rel="${src#$OLD_SITE/}" 87 dest="$NEW_SITE/$rel" 88 mkdir -p "$(dirname "$dest")" 89 cp "$src" "$dest" 90 done 91 notes_count=$(find "$NEW_SITE/notes" -name "*.mld" -type f 2>/dev/null | wc -l) 92 echo " Copied $notes_count .mld files" 93else 94 echo " Skipped (directory empty or does not exist)" 95fi 96 97# 1e. Copy drafts/ if it exists 98echo " Copying drafts/ ..." 99if [ -d "$OLD_SITE/drafts" ] && [ -n "$(ls -A "$OLD_SITE/drafts" 2>/dev/null)" ]; then 100 mkdir -p "$NEW_SITE/drafts" 101 find "$OLD_SITE/drafts" -name "*.mld" -type f | while read -r src; do 102 rel="${src#$OLD_SITE/}" 103 dest="$NEW_SITE/$rel" 104 mkdir -p "$(dirname "$dest")" 105 cp "$src" "$dest" 106 done 107 drafts_count=$(find "$NEW_SITE/drafts" -name "*.mld" -type f 2>/dev/null | wc -l) 108 echo " Copied $drafts_count .mld files" 109else 110 echo " Skipped (directory empty or does not exist)" 111fi 112 113# 1f. Copy reference/ .mld files only (not build output) 114echo " Copying reference/ ..." 115if [ -d "$OLD_SITE/reference" ]; then 116 mkdir -p "$NEW_SITE/reference" 117 find "$OLD_SITE/reference" -name "*.mld" -type f | while read -r src; do 118 rel="${src#$OLD_SITE/}" 119 dest="$NEW_SITE/$rel" 120 mkdir -p "$(dirname "$dest")" 121 cp "$src" "$dest" 122 done 123 ref_count=$(find "$NEW_SITE/reference" -name "*.mld" -type f 2>/dev/null | wc -l) 124 echo " Copied $ref_count .mld files" 125else 126 echo " Skipped (directory does not exist)" 127fi 128 129echo "" 130 131# ============================================================ 132# Step 2: Apply transformations to all .mld files 133# ============================================================ 134 135echo "--- Step 2: Applying transformations ---" 136 137transform_count=0 138libs_count=0 139switch_count=0 140notanotebook_count=0 141autorun_count=0 142ocamltop_plain_count=0 143 144find "$NEW_SITE" -name "*.mld" -type f | sort | while read -r file; do 145 modified=false 146 147 # 2a. Replace {@ocamltop autorun[ with {@ocaml run-on=load[ 148 # This handles variants like: {@ocamltop autorun hidden[ 149 if grep -q '{@ocamltop autorun' "$file" 2>/dev/null; then 150 # Replace {@ocamltop autorun[ with {@ocaml run-on=load[ 151 # Also handle {@ocamltop autorun hidden[ -> {@ocaml run-on=load hidden[ 152 sed -i 's/{@ocamltop autorun\b/{@ocaml run-on=load/g' "$file" 153 modified=true 154 autorun_count=$((autorun_count + 1)) 155 fi 156 157 # Also handle {x@ocamltop autorun[ -> {x@ocaml run-on=load[ 158 if grep -q '{x@ocamltop autorun' "$file" 2>/dev/null; then 159 sed -i 's/{x@ocamltop autorun\b/{x@ocaml run-on=load/g' "$file" 160 modified=true 161 fi 162 163 # Also handle {@ocaml autorun -> {@ocaml run-on=load (non-ocamltop variant) 164 if grep -q '{@ocaml autorun' "$file" 2>/dev/null; then 165 sed -i 's/{@ocaml autorun\b/{@ocaml run-on=load/g' "$file" 166 modified=true 167 fi 168 169 # 2b. Replace {@ocamltop skip[ with {@ocaml skip[ 170 if grep -q '{@ocamltop skip' "$file" 2>/dev/null; then 171 sed -i 's/{@ocamltop skip\b/{@ocaml skip/g' "$file" 172 modified=true 173 fi 174 175 # 2c. Replace remaining {@ocamltop[ with {@ocaml[ 176 if grep -q '{@ocamltop\[' "$file" 2>/dev/null; then 177 sed -i 's/{@ocamltop\[/{@ocaml[/g' "$file" 178 modified=true 179 ocamltop_plain_count=$((ocamltop_plain_count + 1)) 180 fi 181 182 # Also handle {x@ocamltop[ -> {x@ocaml[ 183 if grep -q '{x@ocamltop\[' "$file" 2>/dev/null; then 184 sed -i 's/{x@ocamltop\[/{x@ocaml[/g' "$file" 185 modified=true 186 fi 187 188 # 2d. Transform @libs lines: space-separated to comma-separated @x-ocaml.requires 189 # e.g. @libs pkg1 pkg2 pkg3 -> @x-ocaml.requires pkg1,pkg2,pkg3 190 if grep -q '^@libs ' "$file" 2>/dev/null; then 191 sed -i '/^@libs /{s/^@libs //; s/ /,/g; s/^/@x-ocaml.requires /}' "$file" 192 modified=true 193 libs_count=$((libs_count + 1)) 194 fi 195 196 # 2e. Remove @switch oxcaml lines entirely 197 if grep -q '^@switch ' "$file" 2>/dev/null; then 198 sed -i '/^@switch /d' "$file" 199 modified=true 200 switch_count=$((switch_count + 1)) 201 fi 202 203 # 2f. Remove @notanotebook lines entirely 204 if grep -q '^@notanotebook' "$file" 2>/dev/null; then 205 sed -i '/^@notanotebook$/d' "$file" 206 modified=true 207 notanotebook_count=$((notanotebook_count + 1)) 208 fi 209 210 if [ "$modified" = true ]; then 211 transform_count=$((transform_count + 1)) 212 fi 213done 214 215echo " Files transformed: see summary below" 216echo "" 217 218# ============================================================ 219# Step 3: Flag files for manual review 220# ============================================================ 221 222echo "--- Step 3: Checking for files needing manual review ---" 223echo "" 224 225# 3a. Check for remaining ocamltop (incomplete transformation) 226echo " [CHECK] Files still containing 'ocamltop' (incomplete transformation):" 227remaining_ocamltop=0 228while IFS= read -r file; do 229 rel="${file#$NEW_SITE/}" 230 echo " - $rel" 231 remaining_ocamltop=$((remaining_ocamltop + 1)) 232done < <(grep -rl 'ocamltop' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) 233if [ "$remaining_ocamltop" -eq 0 ]; then 234 echo " (none -- all ocamltop references transformed)" 235fi 236echo "" 237 238# 3b. Check for {x@ocaml[ (deferred blocks needing manual handling) 239echo " [CHECK] Files containing '{x@ocaml[' (deferred blocks, need manual review):" 240deferred_count=0 241while IFS= read -r file; do 242 rel="${file#$NEW_SITE/}" 243 echo " - $rel" 244 deferred_count=$((deferred_count + 1)) 245done < <(grep -rl '{x@ocaml\[' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) 246if [ "$deferred_count" -eq 0 ]; then 247 echo " (none)" 248fi 249echo "" 250 251# 3c. Check for lines starting with # inside code blocks (old prompt prefixes) 252echo " [CHECK] Files with '# ' prompt prefixes inside code blocks (need manual review):" 253prompt_count=0 254while IFS= read -r file; do 255 rel="${file#$NEW_SITE/}" 256 echo " - $rel" 257 prompt_count=$((prompt_count + 1)) 258done < <(grep -rl '^# ' "$NEW_SITE" --include="*.mld" 2>/dev/null || true) 259if [ "$prompt_count" -eq 0 ]; then 260 echo " (none)" 261fi 262echo "" 263 264# ============================================================ 265# Summary 266# ============================================================ 267 268echo "=== Migration Summary ===" 269total_mld=$(find "$NEW_SITE" -name "*.mld" -type f | wc -l) 270total_static=$(find "$NEW_SITE/static" -type f 2>/dev/null | wc -l) 271echo " Total .mld files migrated: $total_mld" 272echo " Total static files copied: $total_static" 273echo "" 274echo " Transformations applied:" 275echo " @ocamltop autorun -> @ocaml run-on=load" 276echo " @ocamltop[ -> @ocaml[" 277echo " @libs -> @x-ocaml.requires (comma-separated)" 278echo " @switch lines removed" 279echo " @notanotebook lines removed" 280echo "" 281echo " Files needing manual review: $((remaining_ocamltop + deferred_count + prompt_count))" 282echo " - Remaining ocamltop: $remaining_ocamltop" 283echo " - Deferred blocks ({x@ocaml[): $deferred_count" 284echo " - Prompt prefixes (# ): $prompt_count" 285echo "" 286echo "=== Done ==="