#!/bin/bash # Current date for the 'updated' field current_date=$(date +%F) # Recursive search for all markdown files in the content folder find ../content -type f -name "*.md" | while read file; do # Check if the file has frontmatter enclosed in +++ if [ "$(head -n 1 "$file")" = "+++" ]; then # Check if the 'date' field exists in the frontmatter if grep -q '^date\s*=' "$file"; then # Check if the 'updated' field is already present if grep -q '^updated\s*=' "$file"; then echo "✘ Skipped: 'updated' field already present in $file" else # Insert updated field directly after the date line without quotes sed -i "" "/^date\s*=.*/a\\ updated = ${current_date} " "$file" echo "✔ Inserted 'updated' after date in $file" fi else echo "✘ No date field found in the frontmatter of $file" fi else echo "✘ No frontmatter found in $file" fi done