awebsite/scripts/convert_alerts_to_github.sh

35 lines
712 B
Bash
Executable file

#!/bin/bash
# Script to convert old alert syntax to GitHub-style alerts
# Change to workspace root
cd "$(dirname "$0")/.."
# File to process
FILE="content/project/2021-03-01-philosophy/index.md"
if [ ! -f "$FILE" ]; then
echo "Error: File not found: $FILE"
exit 1
fi
# Create backup
cp "$FILE" "$FILE.backup"
# Convert {% alert(note=true) %} to > [!NOTE]
# and {% end %} to empty line (removing the closing tag)
# Use sed to do the transformation
sed -i.tmp '
# Convert opening alert tag
s/{% alert(note=true) %}/> [!NOTE]/g
# Remove closing tag
/^{% end %}$/d
' "$FILE"
# Remove temporary file
rm -f "$FILE.tmp"
echo "Conversion complete!"
echo "Backup saved as: $FILE.backup"