paritybit.ca

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

commit 6e690472bb9f6bed69f1dcacd15c00d6fdaaffc2
parent 4afb6680869099013789317bf355a1e4754f0f26
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Thu, 11 Jun 2020 15:55:41 -0400

Fix various basic bugs

Diffstat:
Mpublish | 53++++++++++++++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/publish b/publish @@ -32,6 +32,14 @@ if [ ! -x "$(command -v ed)" ]; then echo "ed 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 [ "$1" = "" ]; then echo "No arguments given; nothing to do." exit 1 @@ -82,21 +90,6 @@ print_info_msg() printf "$CLEAR[ii] %s\n" "$1" } -# Thanks to: https://stackoverflow.com/a/27875395/12865517 -# First argument is the yes/no question to be asked -confirm() -{ - printf "%s [y/N]? " "$1" - 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 - return 1 - fi - return 0 -} - # Populate the [DATE] fields of the blog post populate_date() { @@ -123,7 +116,10 @@ update_home_page() sed -i -e "/<\/div>/a\\ $shortDate \<a class=\"feed-item\" href=\"$basePage\/$fileName\"\>$pageTitle\<\/a\>\n" \ pages/home.md - echo \$'8,$g/### What is a Parity Bit/-2,-1d\nw' | ed -s pages/home.md + echo "/### What is a Parity Bit + 2k2dd + :wq" > /tmp/script.vim + "$vim_ver" -s /tmp/script.vim pages/home.md ./compile -s pages/home.md } @@ -171,9 +167,11 @@ update_sitemap() { print_info_msg "Updating sitemap" echo "$baseURL" > /tmp/base-url.txt - baseURLClean=$(sed -i -e 's/\//\\\//g' /tmp/base-url.txt) + sed -i -e 's/\//\\\//g' /tmp/base-url.txt + baseURLClean=$(cat /tmp/base-url.txt) + echo $baseURLClean sed -i -e "/$baseURLClean</a\\ - <url\>\<loc\>$baseURLClean\/$fileName\<\/loc\>\<\/url\>" \ + <url\>\<loc\>$baseURLClean\/$fileName\<\/loc\>\<\/url\>" \ public/sitemap.xml } @@ -199,7 +197,7 @@ auto_post() accessToken="" meta="$(head -n3 "$file" | tail -n1 \ | cut -d'#' -f2 | sed -e 's/^[[:space:]]*//')" - printf "New Blog Post: %s\n\n%s%s\n\n%s\n\n#100DaysToOffload" \ + printf "New Blog Post: %s\n\n%s/%s\n\n%s\n\n#100DaysToOffload" \ "$pageTitle" "$baseURL" "$fileName" "$meta" > /tmp/status.txt uniqueId="$(md5sum /tmp/status.txt | awk '{print $1}')" @@ -233,8 +231,21 @@ for file in "$@"; do rssEntry="" print_header_msg "PUBLISHING: $file" - confirmed=$(confirm "Are you sure you wish to publish this post?") - [ ! "$confirmed" ] && continue + + # 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