Created
          September 17, 2024 01:46 
        
      - 
      
- 
        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
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This is useful if you want to write your instructions and take your screenshots separately.
Usage, assuming
mpi.shis executable and in your~/bin/directory.The results look like...