paritybit.ca

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

commit 92d8a7a63f948e517880ecd17d89e3d1dfa4658a
parent 0c239c27fff47d63fc40ef95f76174294deb672c
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sat, 11 Apr 2020 23:50:56 -0400

Add auto-upload to compile script

Diffstat:
Mcompile | 106+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 63 insertions(+), 43 deletions(-)

diff --git a/compile b/compile @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -htmldir="public/html" +htmlDir="public/html" cssdir="public/css" mkdir -p "$cssdir" -mkdir -p "$htmldir" +mkdir -p "$htmlDir" for file in $@; do @@ -34,12 +34,12 @@ for file in $@; do continue; fi - filename=$(basename "$file" | cut -f 1 -d '.') - fileextension="${file##*.}" + fileName=$(basename "$file" | cut -f 1 -d '.') + fileExtension="${file##*.}" filedir=$(dirname "$file") - checkfile=$(echo "$filedir" | cut -f 1 -d '/') + removePrefix=$(echo "$filedir" | cut -f 1 -d '/') - if [[ "$fileextension" == "css" ]]; then + if [[ "$fileExtension" == "css" ]]; then tput setaf 3; tput bold; tput smul printf "### MINIFYING CSS...\n\n" @@ -47,52 +47,62 @@ for file in $@; do printf " " tput bold; tput smul - echo "$file > $cssdir/$filename.min.css" + echo "$file > $cssdir/$fileName.min.css" tput sgr0 curl --data "input=`cat $file`" https://cssminifier.com/raw > \ - "$cssdir"/"$filename".min.css + "$cssdir"/"$fileName".min.css if [[ $? != 0 ]]; then printf "\nThere was an issue minifying this CSS." exit 1 fi + # Auto-upload the new css to the site + printf " Uploading new css... " + + cd public && rsync -rR css/"$fileName".min.css \ + paritybit.ca:uploads/ && cd .. + + tput setaf 2; tput bold + echo "[DONE]" + tput sgr0 + echo "" continue fi # Strips "pages" from the file path so pages are saved in the root of - # $htmldir + # $htmlDir if [[ "$filedir" == "pages" ]]; then - savepath="." - elif [[ "$checkfile" == "pages" ]]; then - savepath=$(echo ${filedir#$checkfile/}) + savePath="" + elif [[ "$removePrefix" == "pages" ]]; then + savePath="$(echo ${filedir#$removePrefix/})/" fi # Make the requisite directories in the output and intermediate build folder - if [[ ! -d "$htmldir/$savepath" ]]; then - mkdir -p "$htmldir"/"$savepath" - mkdir -p build/"$savepath" + if [[ ! -d "$htmlDir/$savePath" ]]; then + mkdir -p "$htmlDir"/"$savePath" + mkdir -p build/"$savePath" fi # Compile the file content if valid file name given - if [[ "$file" != "" && ! -d "$file" && "$filename" != "" ]]; then + if [[ "$file" != "" && ! -d "$file" && "$fileName" != "" ]]; then tput setaf 3; tput bold; tput smul - echo "### CREATING: $htmldir/$savepath/$filename.html" + echo "### CREATING: $htmlDir/$savePath$fileName.html" tput sgr0 # Turns the markdown into pure html printf " Compiling page content..." - markdown "$filedir"/"$filename".md > build/"$savepath"/"$filename"-content.html + markdown "$filedir"/"$fileName".md > build/"$savePath"/"$fileName"-content.html tput setaf 2; tput bold echo " [DONE]" tput sgr0 # Combines output from above with pre-compiled header/footer html printf " Constructing full page..." - cat build/header.html > $htmldir/$savepath/$filename.html - cat build/"$savepath"/"$filename"-content.html >> "$htmldir"/"$savepath"/"$filename".html - cat build/footer.html >> "$htmldir"/"$savepath"/"$filename".html + cat build/header.html > $htmlDir/$savePath$fileName.html + cat build/"$savePath"/"$fileName"-content.html >> "$htmlDir"/"$savePath"/"$fileName".html + cat build/footer.html >> "$htmlDir"/"$savePath"/"$fileName".html tput setaf 2; tput bold echo " [DONE]" tput sgr0 @@ -106,23 +116,23 @@ for file in $@; do # Assumes first line of every markdown file is the header in the format: # "## <file_title>" # Sets the html <title> tag to be <file_title>. - filetitle=$(head -n 1 "$filedir"/"$filename".md | cut -d" " -f 2-) + filetitle=$(head -n 1 "$filedir"/"$fileName".md | cut -d" " -f 2-) printf " Setting page title..." sed -i "s/<title>.*<\/title>/<title>${filetitle//&/\\&} - paritybit.ca<\/title>/" \ - "$htmldir"/"$savepath"/"$filename".html + "$htmlDir"/"$savePath"/"$fileName".html tput setaf 2; tput bold echo " [DONE]" tput sgr0 # Assumes the third line of every markdown file is the <meta> tag # information (preceded by '[//]: #') and sets html meta description - metaText=$(sed '3!d' "$filedir"/"$filename".md | cut -d# -f 2) + metaText=$(sed '3!d' "$filedir"/"$fileName".md | cut -d# -f 2) # Remove leading whitespace and forward slash characters metaTextClean=$(echo -e "${metaText}" | sed -e 's/^[[:space:]]*//') metaTextClean=$(sed -e 's/\//\\\//g' <<< "$metaTextClean") printf " Setting description..." sed -i "s/content=\"\"/content=${metaTextClean//&/\\&}/" \ - "$htmldir"/"$savepath"/"$filename".html + "$htmlDir"/"$savePath"/"$fileName".html tput setaf 2; tput bold echo " [DONE]" tput sgr0 @@ -130,7 +140,7 @@ for file in $@; do # Assumes the fifth line of every markdown file defines the requisite # css files (preceded by '[//]: #') and adds link elements as necessary printf " Adding CSS links..." - CSSTags=$(sed '5!d' "$filedir"/"$filename".md | cut -d# -f 2) + CSSTags=$(sed '5!d' "$filedir"/"$fileName".md | cut -d# -f 2) # Remove leading whitespace and quote marks CSSTagsClean=$(echo -e "${CSSTags}" | sed -e 's/^[[:space:]]*//') CSSTagsClean=$(sed -e 's/^"//' -e 's/"$//' <<< "$CSSTagsClean") @@ -139,7 +149,7 @@ for file in $@; do # Add each link element after the <title> tag for CSSFile in "${CSSFileList[@]}"; do sed -i "/<title>/a \ \ \ \ <link rel=\"stylesheet\" href=\"\/css\/$CSSFile\">" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html done tput setaf 2; tput bold echo " [DONE]" @@ -157,7 +167,7 @@ for file in $@; do # # Note: sectionNameNS is the name of the section without any spaces # because the HTML spec says no spaces in href property - toc=$(sed '7!d' "$filedir"/"$filename".md | cut -d# -f 2) + toc=$(sed '7!d' "$filedir"/"$fileName".md | cut -d# -f 2) # Remove leading whitespace and quote marks tocClean=$(echo -e "${toc}" | sed -e 's/^[[:space:]]*//') tocClean=$(sed -e 's/^"//' -e 's/"$//' <<< "$tocClean") @@ -167,8 +177,8 @@ for file in $@; do # Check for an empty array, if it's not empty then populate the TOC if [ ! "${#sections[@]}" -eq "0" ]; then sed -i "/TOC/a <div id=\"table-of-contents\" aria-label=\"Table of Contents\">\n<h2 id=\"toc-title\">Table of Contents</h2>" \ - $htmldir/$savepath/$filename.html - sed -i "/toc-title/a </ul></div>" $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html + sed -i "/toc-title/a </ul></div>" $htmlDir/$savePath$fileName.html for ((i = ${#sections[@]}-1; i >= 0; i--)); do # Remove leading whitespaces sectionName=$(echo -e "${sections[$i]}" | sed -e 's/^[[:space:]]*//') @@ -177,56 +187,66 @@ for file in $@; do sectionName=${sectionName:7} sectionNameNS=$(sed -e 's/ //g' <<< "$sectionName") sed -i "/toc-title/a <ul><ul><li><a href=\"#$sectionNameNS\">$sectionName</a></li></ul></ul>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "/<h5>$sectionName<\/h5>/i </section>\n<section>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "s/<h5>$sectionName<\/h5>/<h5 id=\"$sectionNameNS\">$sectionName<\/h5>/" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html # Check if this is supposed to be a sub-section & add <ul> elif echo "$sectionName" | grep -qi "^sub:"; then sectionName=${sectionName:4} sectionNameNS=$(sed -e 's/ //g' <<< "$sectionName") sed -i "/toc-title/a <ul><li><a href=\"#$sectionNameNS\">$sectionName</a></li></ul>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "/<h4>$sectionName<\/h4>/i </section>\n<section>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "s/<h4>$sectionName<\/h4>/<h4 id=\"$sectionNameNS\">$sectionName<\/h4>/" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html # Otherwise, this is a normal section, no <ul> added else sectionNameNS=$(sed -e 's/ //g' <<< "$sectionName") sed -i "/toc-title/a <li><a href=\"#$sectionNameNS\">$sectionName</a></li>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "/<h3>$sectionName<\/h3>/i </section\>\n<section>" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html sed -i "s/<h3>$sectionName<\/h3>/<h3 id=\"$sectionNameNS\">$sectionName<\/h3>/" \ - $htmldir/$savepath/$filename.html + $htmlDir/$savePath$fileName.html fi done # Closes out the table of contents list - sed -i "/toc-title/a <ul>" $htmldir/$savepath/$filename.html + sed -i "/toc-title/a <ul>" $htmlDir/$savePath$fileName.html # Wraps the beginning of the document (stuff before first section) # in a section by adding the first <section> tag - sed -i "/END OF HEADER FILE/a <section>" $htmldir/$savepath/$filename.html + sed -i "/END OF HEADER FILE/a <section>" $htmlDir/$savePath$fileName.html # Closes out the final section by inserting final </section> tag - sed -i "/<\/main>/i </section>" $htmldir/$savepath/$filename.html + sed -i "/<\/main>/i </section>" $htmlDir/$savePath$fileName.html fi tput setaf 2; tput bold echo " [DONE]" tput sgr0 + # Auto-upload the new page to the site + printf " Uploading page... " + + cd public && rsync -rR html/"$savePath""$fileName".html \ + paritybit.ca:uploads/ && cd .. + + tput setaf 2; tput bold + echo "[DONE]" + tput sgr0 + tput bold - echo -e "### CREATED: $htmldir/$savepath/$filename.html\n" + echo -e "### CREATED: $htmlDir/$savePath$fileName.html\n" tput sgr0 fi done