paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 942cf0752651f25bc6059d5cbf56eee7ff7e5dd9
parent 8822c4e42a101253182a2244cc31917d14bfaceb
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sat, 11 Apr 2020 01:22:44 -0400

Add auto-posting to Mastodon when new post published

Diffstat:
Mpublish | 36++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/publish b/publish @@ -106,7 +106,7 @@ tput sgr0 # Update the RSS feed -printf " Updating RSS feed... " +printf " Updating RSS feed... " mv "$mainFeed" "$mainFeed.bak" head -n 8 "$mainFeed.bak" > "$mainFeed" @@ -129,7 +129,7 @@ tput sgr0 # Upload the new feed plus the new article and updated pages to the website -printf " Uploading pages and feed... " +printf " Uploading pages and feed... " cd public && rsync -rR html/home.html sitemap.xml feeds/sitewide-feed.xml \ "$categoryPage" "$article" "$destination" && cd .. @@ -138,6 +138,38 @@ tput setaf 2; tput bold echo "[DONE]" tput sgr0 + +# Post a status update on Mastodon linking to the new blog post +printf " Posting about it on Mastodon... " +accessToken="<TOKEN_HERE>" +status="$(cat << END +New Blog Post: $(head -n 1 $1 | cut -d" " -f 2-) + +$baseURL/$filename +END +)" +uniqueId="$(md5sum <<< $status | awk '{print $1}')" + +resp="$(curl -s -S -i -X POST \ + -H "Idempotency-Key: $uniqueId" \ + -H "Authorization: Bearer $accessToken" \ + -F status="$status" \ + -F visibility=public \ + https://social.paritybit.ca/api/v1/statuses)" + +httpCode="$(echo "$resp" | grep HTTP/ | awk '{print $2}')" + +if [ "$httpCode" = "200" ]; then + tput setaf 2; tput bold + echo "Status updated successfully." + tput sgr0 +else + tput setaf 1; tput bold + echo "Status failed to update, post manually later:" + tput sgr0 + echo "$resp" +fi + tput bold echo "### PUBLISHED: $filename | Visit: $baseURL/$filename" tput sgr0