Created
December 2, 2024 22:24
-
-
Save firedynasty/2be7ee9cc15fd1fcd1b8ae31fb22f6c9 to your computer and use it in GitHub Desktop.
create markdown syntax for images
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
#function when ran will combine all the images in a folder and post to a file called images.md | |
function createMD() { | |
if [[ $# -eq 0 ]]; then | |
echo "Do you want to create or update the Markdown file? \'images.md\' (y/n): " | |
read confirmation | |
# Check the user's input | |
if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then | |
echo "Operation canceled by the user." | |
return | |
fi | |
# Directory containing the image files (current working directory) | |
image_dir=$(pwd) | |
# Output Markdown file | |
md_file="images.md" | |
# Check if the Markdown file exists; if not, create it | |
if [[ ! -f "$image_dir/$md_file" ]]; then | |
touch "$image_dir/$md_file" | |
echo "Created new Markdown file: $md_file" | |
else | |
echo "Updating existing Markdown file: $md_file" | |
fi | |
# Generate the list of image files (jpg, png, gif) in the current directory | |
find "$image_dir" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" \) | sort > /tmp/image_list.txt | |
# Debugging: Check if the temporary file has content | |
if [[ ! -s /tmp/image_list.txt ]]; then | |
echo "No image files found in the directory: $image_dir" | |
rm -f /tmp/image_list.txt | |
return | |
fi | |
# Append the Markdown image links to the file | |
while IFS= read -r image_path; do | |
# Extract the file name without extension | |
image_name=$(basename "$image_path") | |
# Append the Markdown image link and image name to the Markdown file | |
echo "" >> "$md_file" | |
echo "${image_name%.*}:" >> "$md_file" | |
done < /tmp/image_list.txt | |
# Cleanup temporary file | |
rm -f /tmp/image_list.txt | |
echo "Markdown file created/updated at: $image_dir/$md_file" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment