squeeze

A static site generator that can put the toothpaste back in the tube.
git clone https://git.stjo.hn/squeeze
Log | Files | Refs | README | LICENSE

commit 9bf102a4a279cfb57d7db352ceda9f6356de012f
parent 4b5050282f7ba54cf76fc53a77242bb7a30c4516
Author: St John Karp <contact@stjo.hn>
Date:   Wed, 22 Apr 2020 17:03:51 -0500

Tidy bash scripts

Tidied up the bash scripts with more verbose options, braces, etc.

Diffstat:
Msqueeze.sh | 42+++++++++++++++++++++---------------------
Munsqueeze.sh | 22++++++++++++----------
2 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/squeeze.sh b/squeeze.sh @@ -10,33 +10,33 @@ SITE_PATH=$1 rsync --archive --delete --verbose --exclude "*.md" --exclude "*.html" --exclude "feeds" "$SITE_PATH/$SOURCE_DIR/" "$SITE_PATH/$OUTPUT_DIR/" # Delete any HTML files for which the source was removed. -find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" -print0 | - while IFS= read -r -d '' file; do - OLD_PATH=`echo "$file" | +find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" | + while read -r file; do + OLD_PATH=$(echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | - sed 's|.html$|.md|'` - if [ ! -f $OLD_PATH ]; then - rm $file + sed 's|.html$|.md|') + if [ ! -f "$OLD_PATH" ]; then + rm "$file" fi done # Parse and create all the HTML files. -find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" -print0 | - while IFS= read -r -d '' file; do - NEW_PATH=`echo "$file" | +find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" | + while read -r file; do + NEW_PATH=$(echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | - sed 's|.md$|.html|'` + sed 's|.md$|.html|') # Only process files whose destination doesn't exist, or which has been recently changed. - if [ ! -f $NEW_PATH ] || [[ $(find $file -mtime -7) ]]; then - echo $file + if [ ! -f "$NEW_PATH" ] || [[ $(find "$file" -mtime -7) ]]; then + echo "$file" # Get everything after the metadata. sed "1,/^$/d" "$file" | # Convert Markdown to HTML. markdown | # Recombine with the metadata and hand it to Prolog. (sed "/^$/q" "$file" && cat) | - swipl --traditional -q -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | - # Smarten remaining punctuation (e.g. parts of the template). + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | + # Smarten punctuation. smartypants \ > "$NEW_PATH" fi @@ -45,19 +45,19 @@ find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" -print0 | # Generate the RSS feed. mkdir -p "$SITE_PATH/$OUTPUT_DIR/feeds" # Grep the date of each article. -ARTICLES=`grep -R --include=\*.md "^Date: " "$SITE_PATH/$SOURCE_DIR" | +ARTICLES=$(grep --recursive --include=\*.md "^Date: " "$SITE_PATH/$SOURCE_DIR" | # Reformat the output so the date comes first, then the file name. - sed -rn 's/^([^:]+):(.+)$/\2\t\1/p' | + sed --quiet --regexp-extended 's/^([^:]+):(.+)$/\2\t\1/p' | # Sort articles by date. sort | # Reformat to just the file names. - cut -f2 | + cut --fields=2 | # Get the last (i.e. most recent) posts for the RSS feed. tail -5 | # Glue the file names together to be passed to Prolog. - paste -sd ',' - | - sed "s|,|','|g"` -BUILD_DATE=`date +"%Y-%m-%d %T"` + paste --serial --delimiters=',' - | + sed "s|,|','|g") +BUILD_DATE=$(date +"%Y-%m-%d %T") # Parse the articles and generate the RSS. -swipl --traditional -q -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." \ +swipl --traditional --quiet -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." \ > "$SITE_PATH/$OUTPUT_DIR/feeds/rss.xml" diff --git a/unsqueeze.sh b/unsqueeze.sh @@ -11,22 +11,24 @@ SITE_PATH=$1 rsync --archive --delete --verbose --exclude "*.html" --exclude "*.md" --exclude "feeds" "$SITE_PATH/$OUTPUT_DIR/" "$SITE_PATH/$SOURCE_DIR/" # Delete any Markdown files for which the output was removed. -find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" -print0 | - while IFS= read -r -d '' file; do - OLD_PATH=`echo "$file" | +find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" | + while read -r file; do + OLD_PATH=$(echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | - sed 's|.md$|.html|'` - if [ ! -f $OLD_PATH ]; then - rm $file + sed 's|.md$|.html|') + if [ ! -f "$OLD_PATH" ]; then + rm "$file" fi done # Parse and create all the markdown files. -find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" -print0 | - while IFS= read -r -d '' file; do - NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | sed 's|.html$|.md|'` +find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" | + while read -r file; do + NEW_PATH=$(echo "$file" | + sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | + sed 's|.html$|.md|') cat "$file" | - swipl --traditional -q -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry." | + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry." | # Unsmarten the punctuation. sed "s|&nbsp;| |g" | sed "s|&#8216;|'|g" |