#!/bin/bash

# Regex pattern for ISO date format filenames like 2019-06-01-something.md
pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.+\.md$'

echo "Processing markdown files in $(pwd)"
echo

for file in *.md; do
  # Skip if no matching files (glob doesn't find anything)
  [ -e "$file" ] || continue

  if [[ "$file" =~ $pattern ]]; then
    basename="${file%.md}"
    mkdir -p "$basename"
    mv "$file" "$basename/index.md"
    echo "✔ Processed: $file  →  $basename/index.md"
  else
    echo "✘ Skipped (pattern mismatch): $file"
  fi
done
