Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Created March 4, 2024 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreagrandi/800e5e33ec05f8d51f61a1cdc4fc4d91 to your computer and use it in GitHub Desktop.
Save andreagrandi/800e5e33ec05f8d51f61a1cdc4fc4d91 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script is necessary to remove the annotations block from each Markdown file.
# These annotations are being written by iA Writer and are not necessary for the website.
# Define the directory to start searching from. Adjust this to your specific folder.
START_DIR="content"
# Process each Markdown file in the specified directory and its subfolders.
find "$START_DIR" -type f -name "*.md" | while read -r file; do
echo "Processing: $file"
# Use awk to skip the annotations block as described.
awk '
/^---$/ {
getline;
if ($0 ~ /^Annotations:/) skip_block=1
}
skip_block && /^...$/ {
skip_block=0;
next;
}
!skip_block { print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo "Finished processing: $file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment