From 871de43c9e029cd70ad119f46383ab9ba57464cb Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 6 Aug 2023 22:12:27 +0800 Subject: [PATCH] autogenerate image dir --- post.sh | 7 ++++--- push.sh | 12 +++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/post.sh b/post.sh index c470878..007b40c 100755 --- a/post.sh +++ b/post.sh @@ -27,8 +27,8 @@ sanitized_title=$(sanitize_title "$user_title") # Generate the filename with the current date current_date=$(date +'%Y-%m-%d') -filename="${current_date}-${sanitized_title}.md" -filepath="_posts/${filename}" +filename="${current_date}-${sanitized_title}" +filepath="_posts/${filename}.md" # Check if the file already exists if [ -e "$filepath" ]; then @@ -36,5 +36,6 @@ if [ -e "$filepath" ]; then else # Create the new file and add the front matter generate_front_matter "$user_title" > "$filepath" - echo "File '$filename' created successfully in the '_posts' subdirectory." + mkdir -p "assets/img/${filename}" + echo "File '$filename.md' created successfully in the '_posts' subdirectory." fi diff --git a/push.sh b/push.sh index 135e8e0..8cbc771 100755 --- a/push.sh +++ b/push.sh @@ -11,14 +11,20 @@ generate_commit_message() { } commit_msg="$(generate_commit_message)" +new_posts="$(get_new_posts)" # Check if there are any new or modified files to commit -if [ -n "$(get_new_posts)" ]; then +if [ -n "$new_posts" ]; then # Add all new and modified files echo "$commit_msg" - git add $(get_new_posts) + git add $new_posts + for post in $new_posts; do + echo $post + post="${post#_posts/}" + git add "assets/img/${post%.md}" + done - # Commit the changes with the generated message + Commit the changes with the generated message git commit -m "$commit_msg" git push echo "Changes committed successfully."