commit e4a5d36bdd28904fcabb0948194693f2f817829e
parent 6ac67736fb69ffa9c3d9474ef83487a8a8daac40
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Mon, 8 Nov 2021 03:25:14 -0500
Hack publish script (last time it should be used tbh)
Diffstat:
M | publish | | | 109 | +++++++++++++++++++++---------------------------------------------------------- |
1 file changed, 28 insertions(+), 81 deletions(-)
diff --git a/publish b/publish
@@ -26,14 +26,6 @@ if [ ! -x "$(command -v rsync)" ]; then
echo "rsync is needed but was not found."
exit 1
fi
-if [ -x "$(command -v nvim)" ]; then
- vim_ver="nvim"
-elif [ ! -x "$(command -v vim)" ]; then
- vim_ver="vim"
-else
- echo "Either vim or nvim is needed but was not found."
- exit 1
-fi
if [ -z "$1" ]; then
echo "No arguments given; nothing to do."
exit 1
@@ -48,7 +40,7 @@ YELLOW="\033[0;33m"
# The RSS feed to edit
mainFeed="public/feeds/sitewide-feed.xml"
# Where to upload files
-remote="paritybit.ca:uploads/"
+remote="paritybit.ca:/var/www/paritybit.ca/"
# The main base page on the site
baseURL="https://www.paritybit.ca/blog"
# Name of the base page
@@ -57,36 +49,18 @@ basePage="blog"
categoryPage="html/blog.html"
# Set to false to disable auto uploading files
autoUpload="true"
-# Set to false to disable auto posting statuses on Mastodon
-autoPost="true"
-# Social media API endpoint
-socialMediaURL="https://pleroma.paritybit.ca/api/v1/statuses"
-# Social media API access token
-accessToken=""
# Prints the message passed as the 1st argument in red.
-print_error_msg()
-{
- printf "$RED[ee] %s\n$CLEAR" "$1"
-}
+print_error_msg() { printf "$RED[ee] %s\n$CLEAR" "$1"; }
# Prints the message passed as the 1st argument in green.
-print_success_msg()
-{
- printf "$GREEN[ok] %s\n$CLEAR" "$1"
-}
+print_success_msg() { printf "$GREEN[ok] %s\n$CLEAR" "$1"; }
# Prints the message passed as the 1st argument in yellow.
-print_header_msg()
-{
- printf "$YELLOW[hh] %s\n$CLEAR" "$1"
-}
+print_header_msg() { printf "$YELLOW[hh] %s\n$CLEAR" "$1"; }
# Prints the message passed as the 1st argument with default colours.
-print_info_msg()
-{
- printf "$CLEAR[ii] %s\n" "$1"
-}
+print_info_msg() { printf "$CLEAR[ii] %s\n" "$1"; }
# Populate the [DATE] fields of the blog post
populate_date()
@@ -99,11 +73,7 @@ populate_date()
# Update the main blog list page
update_base_page()
{
- print_info_msg "Updating base page"
- awk -v pt="$pageTitle" -v bp="$basePage" -v f="$fileName" -v d="$shortDate" \
- '{print} /^<ul>/ && !n {print " <li>"d" <a href=\""bp"/"f"\">"pt"</a></li>"; n++}' \
- pages/"$basePage".md > tmp.md && mv tmp.md pages/"$basePage".md
- ./compile -n pages/$basePage.md
+ print_info_msg "MAKE SURE TO UPDATE THE BLOG PAGE WITH A NEW ENTRY."
}
@@ -169,41 +139,33 @@ auto_upload()
"$categoryPage" "$article" "$remote" && cd ..
}
-# Post a status update on Pleroma linking to the new blog post
+# Create a social media post linking to the new blog post
auto_post()
{
- if [ "$autoPost" != "true" ]; then
- return 0
- fi
-
print_info_msg "Generating social media post"
meta="$(head -n3 "$file" | tail -n1 \
| cut -d'#' -f2 | sed -e 's/^[[:space:]]*//')"
- gmiBaseURL="$(echo "$baseURL" | sed 's/https:\/\/www\./gemini:\/\//')"
- gmiFileName="$(echo "$fileName" | sed 's/$/.gmi/')"
- printf "New Blog Post: %s\n\n%s/%s\n%s/%s\n\n%s" \
- "$pageTitle" "$baseURL" "$fileName" "$gmiBaseURL" "$gmiFileName" \
- "$meta" > /tmp/status.txt
- uniqueId="$(md5sum /tmp/status.txt | awk '{print $1}')"
-
- echo ""
+ printf "New Blog Post: %s\n\n%s/%s\n%s" \
+ "$pageTitle" "$baseURL" "$fileName" "$meta" > /tmp/status.txt
+
+ echo "==="
cat /tmp/status.txt
- echo ""
-
- resp="$(curl -s -S -i -X POST \
- -H "Idempotency-Key: $uniqueId" \
- -H "Authorization: Bearer $accessToken" \
- -F status="$(cat /tmp/status.txt)" \
- -F visibility=public \
- "$socialMediaURL")"
- httpCode="$(echo "$resp" | grep HTTP/ | awk '{print $2}')"
-
- if [ "$httpCode" = "200" ]; then
- print_success_msg "Successfully posted status update"
- else
- print_error_msg "ERROR: Failed to post status update"
- echo "$resp"
- fi
+ echo "==="
+ echo "COPY PASTE THE ABOVE AND MAKE A POST"
+
+ # resp="$(curl -s -S -i -X POST \
+ # -H "Authorization: Bearer $accessToken" \
+ # -F status="$(cat /tmp/status.txt)" \
+ # -F visibility=public \
+ # "$socialMediaURL")"
+ # httpCode="$(echo "$resp" | grep HTTP/ | awk '{print $2}')"
+
+ # if [ "$httpCode" = "200" ]; then
+ # print_success_msg "Successfully posted status update"
+ # else
+ # print_error_msg "ERROR: Failed to post status update"
+ # echo "$resp"
+ # fi
}
for file in "$@"; do
@@ -214,28 +176,13 @@ for file in "$@"; do
date=$(date +"%a, %d %b %Y %T %z")
shortDate=$(date +"%F")
- fileName=$(basename -s .md -- "$file")
+ fileName=$(basename "$file" .md)
pageTitle=$(head -n 1 "$file" | cut -d' ' -f2-)
article="html/blog/$fileName.html"
rssEntry=""
print_header_msg "PUBLISHING: $file"
- # Thanks to: https://stackoverflow.com/a/27875395/12865517
- printf "Are you sure you wish to publish this post? [y/N]: "
- old_stty_cfg=$(stty -g)
- stty raw -echo
- answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
- stty "$old_stty_cfg"
- if echo "$answer" | grep -iq "^y" ;then
- echo ""
- print_success_msg "Publishing..."
- else
- echo ""
- print_error_msg "Refusing to publish"
- continue
- fi
-
populate_date
update_base_page
create_rss_entry