Skip to content

Instantly share code, notes, and snippets.

@stephen-w-pracy
Created September 17, 2024 01:46
Show Gist options
  • Save stephen-w-pracy/5ae820d6116ba50958374f056bb1f2d3 to your computer and use it in GitHub Desktop.
Save stephen-w-pracy/5ae820d6116ba50958374f056bb1f2d3 to your computer and use it in GitHub Desktop.
A shell script to make placeholder images for those linked in Instruqt assignment.md files
#!/bin/bash
# Requires imagemagick. `brew install imagemagick`
# Make Placeholder Images (MPI)
find . -type f -name "assignment.md" | while read md_file; do
# Extract the directory where the current markdown file is located
dir=$(dirname "$md_file")
# Parse the markdown file for image links
grep '!\[.*\](.*)' "$md_file" | while read -r img_link; do
# Extract the image file path from the markdown image link
img_path=$(echo "$img_link" | sed -n 's/.*](\([^)]*\)).*/\1/p')
# Form the full path of the image in the ../assets/ directory
img_filename=$(basename "$img_path")
img_full_path="$dir/../assets/$img_filename"
# Check if the image exists in the ../assets/ directory
if [ ! -f "$img_full_path" ]; then
echo "Image $img_full_path not found. Creating placeholder."
# Create the ../assets directory if it doesn't exist
mkdir -p "$dir/../assets"
# Create a placeholder image with ImageMagick
magick convert -size 800x600 xc:purple -gravity center \
-pointsize 30 -fill white -annotate 0 "$img_filename" \
"$img_full_path"
fi
done
done
@stephen-w-pracy
Copy link
Author

This is useful if you want to write your instructions and take your screenshots separately.

Usage, assuming mpi.sh is executable and in your ~/bin/ directory.

cd labs
~/bin/mpi.sh 

The results look like...

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment