paritybit.ca

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

commit 6f6d3148ffa8e846c3fa58bf7bc25593073e4e74
parent 5c4735edfe7da955ddf9b1e0c3f7fd7587e58aaf
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Thu, 19 Dec 2019 11:39:03 -0500

Improve documentation for createpages script

Diffstat:
Mcreatepages.sh | 40++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/createpages.sh b/createpages.sh @@ -1,6 +1,8 @@ #!/bin/bash - -# Builds the html pages given as command line arguments +# +# Hand-written script to build webpages and minify CSS for the paritybit.ca +# website. +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -44,6 +46,7 @@ if [[ $1 == '-c' || $1 == '--css' ]]; then curl --data "input=`cat $file`" https://cssminifier.com/raw > \ "$cssdir"/"$fileName".min.css if [[ $? != 0 ]]; then + printf "\nThere was an issue minifying the CSS." exit 1 fi echo "" @@ -90,17 +93,22 @@ for page in $@; do # Combines output from above with pre-compiled header/footer html printf " Constructing full page..." - > "$htmldir"/"$savepath"/"$pagename".html - cat build/header.html >> $htmldir/$savepath/$pagename.html + cat build/header.html > $htmldir/$savepath/$pagename.html cat build/"$savepath"/"$pagename"-content.html >> "$htmldir"/"$savepath"/"$pagename".html cat build/footer.html >> "$htmldir"/"$savepath"/"$pagename".html tput setaf 2; tput bold echo " [DONE]" tput sgr0 + # ====================================================================== + # Now that the page is compiled, changes are made to it to properly + # populate the <title>, <meta>, <link> (for css), and table of contents + # fields of the html file. + # ====================================================================== + # Assumes first line of every markdown file is the header in the format: - # "## Title of The Page" - # And sets the html title tag to be the content of that first line + # "## <page_title>" + # And sets the html <title> tag to be <page_title>. pagetitle=$(head -n 1 "$pagedir"/"$pagename".md | cut -f 2- -d " ") printf " Setting page title..." sed -i "s/<title>.*<\/title>/<title>${pagetitle//&/\\&}<\/title>/" \ @@ -112,9 +120,8 @@ for page in $@; do # Assumes the third line of every markdown file is the <meta> tag # information (preceded by '[//]: #') and sets html meta tag as such metaText=$(sed '3!d' "$pagedir"/"$pagename".md | cut -d# -f 2) - # Remove leading whitespace + # Remove leading whitespace and forward slash characters metaTextClean=$(echo -e "${metaText}" | sed -e 's/^[[:space:]]*//') - # Remove any forward slash characters metaTextClean=$(sed -e 's/\//\\\//' <<< "$metaTextClean") printf " Setting meta tag..." sed -i "s/content=\"\"/content=${metaTextClean//&/\\&}/" \ @@ -142,7 +149,7 @@ for page in $@; do tput sgr0 # Assumes the seventh line of every markdown file defines the sections - # to add to a table of contents. + # to add to a table of contents (preceded by '[//]: #'). toc=$(sed '7!d' "$pagedir"/"$pagename".md | cut -d# -f 2) # Remove leading whitespace and quote marks tocClean=$(echo -e "${toc}" | sed -e 's/^[[:space:]]*//') @@ -150,7 +157,7 @@ for page in $@; do printf " Parsing table of contents..." # Split the line into separate entries, separated by a semicolon IFS=';' read -r -a sections <<< "$tocClean" - # Check to see if the size of the array is zero, if so, do nothing + # Check for an empty array, if it's not empty then populate the TOC if [ ! "${#sections[@]}" -eq "0" ]; then # Add a horizontal rule and heading sed -i "/TOC/a <h3 id=\"toc-title\">Table of Contents</h3>" \ @@ -159,9 +166,13 @@ for page in $@; do $htmldir/$savepath/$pagename.html # Add each section to list after the h3 tag (done in reverse order # because lines are appended immediately after the h3 tag) and add - # a link destination to the header of that section + # an internal link to the header of that section as well as a + # "back-to-top" arrow beside each regular section header. + # + # Note: sectionNameNS is the name of the section without any spaces + # because the HTML spec says no spaces in href property sed -i "/toc-title/a </ul>" $htmldir/$savepath/$pagename.html - for ((i=${#sections[@]}-1; i>=0; i--)); do + for ((i = ${#sections[@]}-1; i >= 0; i--)); do # Remove leading whitespaces sectionName=$(echo -e "${sections[$i]}" | sed -e 's/^[[:space:]]*//') # Check if this is supposed to be a sub-sub-section & add 2x<ul> @@ -170,13 +181,13 @@ for page in $@; do sectionNameNS=$(sed -e 's/ //g' <<< "$sectionName") sed -i "/toc-title/a <ul><ul><li><a href=\"#$sectionNameNS\">$sectionName</a></li></ul></ul>" \ $htmldir/$savepath/$pagename.html - # Or a sub-section + # 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/$pagename.html - # Or just a regular section + # Otherwise, this is a normal section else sectionNameNS=$(sed -e 's/ //g' <<< "$sectionName") sed -i "/toc-title/a <li><a href=\"#$sectionNameNS\">$sectionName</a></li>" \ @@ -187,6 +198,7 @@ for page in $@; do $htmldir/$savepath/$pagename.html fi done + # Closes out the table of contents list sed -i "/toc-title/a <ul>" $htmldir/$savepath/$pagename.html fi tput setaf 2; tput bold