paritybit.ca

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

commit ceb47fe5db2a5b2d65979bb0d682f89603d02937
parent 0eae3a81866c500b30c2c5dc07b91217864497c9
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Mon, 30 Dec 2019 13:27:46 -0500

Clean up publish script

Remove unnecessary if-elif-else statements and consolidate most variable
creation in initial check for -b|-p|-g.

Get rid of progress option for rsync because the output isn't really
helpful and looks messy.

Diffstat:
Mpublish | 96+++++++++++++++++++++++++++++--------------------------------------------------
1 file changed, 35 insertions(+), 61 deletions(-)

diff --git a/publish b/publish @@ -22,31 +22,54 @@ # $1 = flag which determines which action to take # $2 = file to act upon +if [ ! -f "$2" ]; then + echo "File $2 not found." + exit 2 +fi + +if [ ! -x "$(command -v rsync)" ]; then + echo "rsync is needed but was not found." + exit 3 +fi + +if [ ! -x "$(command -v ed)" ]; then + echo "ed is needed but was not found." + exit 3 +fi + mainFeed="public/feeds/sitewide-feed.xml" -blogFeed="public/feeds/blog-feed.xml" -projectsFeed="public/feeds/projects-feed.xml" -guidesFeed="public/feeds/guides-feed.xml" descriptionFile="/tmp/publish-description.txt" destination="paritybit.ca:uploads/" +date=$(date +"%a, %d %b %Y %T %z") +miniDate=$(date +"%F") +filename=$(basename -s .md -- "$2") +pageTitle=$(head -n 1 "$2" | cut -d' ' -f2-) +entry="" if [ "$1" = "-b" ]; then publishBlog=1 baseURL="https://www.paritybit.ca/blog" basePage="blog" - categoryFeed=${blogFeed} + categoryPage="html/blog.html" newString="New Blog Post:" + article="html/blog/$filename.html" + feed="feeds/blog-feed.xml" elif [ "$1" = "-p" ]; then publishProject=1 baseURL="https://www.paritybit.ca/projects" basePage="projects" - categoryFeed=${projectsFeed} newString="New Project:" + categoryPage="html/projects.html" + article="html/projects/$filename.html" + feed="feeds/projects-feed.xml" elif [ "$1" = "-g" ]; then publishGuide=1 baseURL="https://www.paritybit.ca/guides" basePage="guides" - categoryFeed=${guidesFeed} newString="New Guide:" + categoryPage="html/guides.html" + article="html/guides/$filename.html" + feed="feeds/guides-feed.xml" else cat << EOF Usage: publish <-b|-p|-g> <page_to_publish> @@ -62,27 +85,6 @@ EOF exit 1 fi -if [ ! -f "$2" ]; then - echo "File $2 not found." - exit 2 -fi - -if [ ! -x "$(command -v rsync)" ]; then - echo "rsync is needed but was not found." - exit 3 -fi - -if [ ! -x "$(command -v ed)" ]; then - echo "ed is needed but was not found." - exit 3 -fi - -date=$(date +"%a, %d %b %Y %T %z") -miniDate=$(date +"%F") -filename=$(basename -s .md -- "$2") -pageTitle=$(head -n 1 "$2" | cut -d' ' -f2-) -entry="" - # Make sure that there is an up-to-date compiled version of the page ./compile "$2" @@ -118,19 +120,8 @@ printf " Creating RSS <item>... " entry="${entry}<item>" # Set <title> -if [ $publishBlog ]; then - entry="${entry} - <title>$newString $pageTitle</title>" -elif [ $publishProject ]; then - entry="${entry} - <title>$newString $pageTitle</title>" -elif [ $publishGuide ]; then - entry="${entry} +entry="${entry} <title>$newString $pageTitle</title>" -else - echo "Something went very wrong... (<title>)" - exit -1 -fi # Set <link> and <guid> entry="${entry} @@ -175,10 +166,10 @@ head -n 8 "$mainFeed.bak" > "$mainFeed" echo "$entry" >> "$mainFeed" tail -n +9 "$mainFeed.bak" >> "$mainFeed" -mv "$categoryFeed" "$categoryFeed.bak" -head -n 8 "$categoryFeed.bak" > "$categoryFeed" -echo "$entry" >> "$categoryFeed" -tail -n +9 "$categoryFeed.bak" >> "$categoryFeed" +mv "public/$feed" "public/$feed.bak" +head -n 8 "public/$feed.bak" > "public/$feed" +echo "$entry" >> "public/$feed" +tail -n +9 "public/$feed.bak" >> "public/$feed" tput setaf 2; tput bold echo "[DONE]" @@ -187,24 +178,7 @@ tput sgr0 # Upload the new feeds plus the new article and updated pages to the website printf " Uploading pages and feeds... " -if [ $publishBlog ]; then - categoryPage="html/blog.html" - article="html/blog/$filename.html" - feed="feeds/blog-feed.xml" -elif [ $publishProject ]; then - categoryPage="html/projects.html" - article="html/projects/$filename.html" - feed="feeds/projects-feed.xml" -elif [ $publishGuide ]; then - categoryPage="html/guides.html" - article="html/guides/$filename.html" - feed="feeds/guides-feed.xml" -else - echo "Something went very wrong... (uploading files)" - exit -1 -fi - -cd public && rsync --progress -rR html/home.html feeds/sitewide-feed.xml $feed $categoryPage $article $destination && cd .. +cd public && rsync -rR html/home.html feeds/sitewide-feed.xml $feed $categoryPage $article $destination && cd .. tput setaf 2; tput bold echo "[DONE]"