peter-tanner.github.io/push.sh

41 lines
938 B
Bash
Raw Permalink Normal View History

2023-08-06 01:08:38 +08:00
#!/bin/bash
get_new_posts() {
git status --porcelain=v1 _posts | grep -E '^\?\?' | cut -d ' ' -f 2 | tr '\n' ' '
}
# Function to generate the commit message
generate_commit_message() {
printf "New posts: "
get_new_posts
}
commit_msg="$(generate_commit_message)"
2023-08-06 22:12:27 +08:00
new_posts="$(get_new_posts)"
2023-08-06 01:08:38 +08:00
# Check if there are any new or modified files to commit
2023-08-06 22:12:27 +08:00
if [ -n "$new_posts" ]; then
./generate-preview-images.sh
2023-08-06 01:08:38 +08:00
# Add all new and modified files
echo "$commit_msg"
2023-08-06 22:12:27 +08:00
git add $new_posts
for post in $new_posts; do
echo $post
2023-08-09 20:38:56 +08:00
sed 's|](../|](/|' -i "$post" # make markdown images absolute
2023-08-06 22:12:27 +08:00
post="${post#_posts/}"
2023-08-09 20:38:56 +08:00
post="${post%.md}"
git add "assets/img/${post:0:31}"
2023-08-06 22:12:27 +08:00
done
2023-08-06 01:08:38 +08:00
2023-10-16 00:58:15 +08:00
# Commit the changes with the generated message
git commit -m "$commit_msg"
2023-08-06 01:08:38 +08:00
git push
echo "Changes committed successfully."
else
echo "No new or modified files to commit."
fi