hugosoucycc

[ARCHIVED] Another old source code of <hugo.soucy.cc>.
Log | Files | Refs | Submodules

commit bcc041d50676376f58d532586b567c40103101a7
parent c135bc5ccf7d5ceefbbe5fd1e05b3c28ebed72bd
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat,  6 Aug 2016 16:56:42 -0400

Follow best pratices from shellcheck.

Diffstat:
Mfunctions/build-pandoc-templates.sh | 6+++---
Mfunctions/clean-content-folder.sh | 4++--
Mfunctions/create-html-pages.sh | 50+++++++++++++++++++++++++-------------------------
Mfunctions/create-html-sections.sh | 43+++++++++++++++++++++----------------------
Mfunctions/get-static-files.sh | 2+-
Mfunctions/move-html-to-publichtml.sh | 2+-
6 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/functions/build-pandoc-templates.sh b/functions/build-pandoc-templates.sh @@ -5,13 +5,13 @@ build_pandoc_templates () { echo "- Convert Mustache templates into Pandoc templates" # Purge the $TPL_PANDOC_PATH/ folder before the conversion - rm -Rf $TPL_PANDOC_PATH/*.html + rm -Rf "$TPL_PANDOC_PATH/"*.html - for mustache in $TPL_MUSTACHE_PATH/*.mustache; do + for mustache in "$TPL_MUSTACHE_PATH/"*.mustache; do # Remove files path mustachename=$(basename "$mustache") # And then the convertion without the mustache extension - mo $mustache > $TPL_PANDOC_PATH/${mustachename%.*}.html + mo "$mustache" > "$TPL_PANDOC_PATH/${mustachename%.*}".html done # End } diff --git a/functions/clean-content-folder.sh b/functions/clean-content-folder.sh @@ -4,10 +4,10 @@ clean_content_folder () { echo "- Clean the content/ folder from all the HTML files" - find $CONTENT_PATH/ -name \*.html -type f -delete + find "$CONTENT_PATH/" -name \*.html -type f -delete # After that remove empty directories echo "- Clean the content/ folder from all the empty directories" - find $CONTENT_PATH/ -type d -empty -delete + find "$CONTENT_PATH/" -type d -empty -delete } diff --git a/functions/create-html-pages.sh b/functions/create-html-pages.sh @@ -8,21 +8,21 @@ create_html_pages () { echo "- Create all the HTML pages with pandoc" get_pandoc_templates - + # Create the homepage - pandoc --template=$TPL_PANDOC_PATH/index.html \ - -o $CONTENT_PATH/index.html $CONTENT_PATH/index.md + pandoc --template="$TPL_PANDOC_PATH/index.html" \ + -o "$CONTENT_PATH/index.html" "$CONTENT_PATH/index.md" # Then create others - for markdown in $(find $CONTENT_PATH/ -mindepth 2 -type f -name \*.md); do + for markdown in $(find "$CONTENT_PATH/" -mindepth 2 -type f -name \*.md); do # Parent folder name without path - section=$(basename $(dirname "$markdown")) + page_section=$(basename "$(dirname "$markdown")") # Markdown files names without path outputname=$(basename "$markdown") # Parse the YAML block of the markdown - eval $(parse_yaml $markdown "config_") + eval "$(parse_yaml "$markdown" "config_")" if [[ "$config_date" != "null" ]]; then # Get year and month @@ -30,38 +30,38 @@ create_html_pages () { month=${config_date:5:2} # First create year and month folders - mkdir -p $(dirname "$markdown")/$year/$month + mkdir -p "$(dirname "$markdown")"/"$year"/"$month" fi - pagepath=$year/$month/${outputname%.*} + page_path="$year"/"$month"/"${outputname%.*}" # Check if a section have a specific template or use the default template - if [[ " ${templates[*]} " == *" $section "* ]]; then + if [[ " ${templates[*]} " == *" $page_section "* ]]; then # Check if the date property value is not "null" if [[ "$config_date" != "null" ]]; then - pandoc -s $markdown \ - --template=$TPL_PANDOC_PATH/${section}.html \ - --variable=modified:$(date -r $markdown +%Y-%m-%dT%H:%M:%S) \ - --variable=permalink:$BASE_URL/$section/$pagepath.html \ - -o $(dirname "$markdown")/$pagepath.html + pandoc -s "$markdown" \ + --template="$TPL_PANDOC_PATH/${page_section}.html" \ + --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \ + --variable=permalink:"$BASE_URL/$page_section/$page_path.html" \ + -o "$(dirname "$markdown")/$page_path.html" else - pandoc -s $markdown \ - --template=$TPL_PANDOC_PATH/${section}.html \ - -o $(dirname "$markdown")/${outputname%.*}.html + pandoc -s "$markdown" \ + --template="$TPL_PANDOC_PATH/${page_section}.html" \ + -o "$(dirname "$markdown")/${outputname%.*}.html" fi else if [[ "$config_date" != "null" ]]; then - pandoc -s $markdown \ - --template=$TPL_PANDOC_PATH/default.html \ - --variable=modified:$(date -r $markdown +%Y-%m-%dT%H:%M:%S) \ - --variable=permalink:$BASE_URL/$section/$pagepath.html \ - -o $(dirname "$markdown")/$pagepath.html + pandoc -s "$markdown" \ + --template="$TPL_PANDOC_PATH/default.html" \ + --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \ + --variable=permalink:"$BASE_URL/$page_section/$page_path.html" \ + -o "$(dirname "$markdown")/$page_path.html" else - pandoc -s $markdown \ - --template=$TPL_PANDOC_PATH/default.html \ - -o $(dirname "$markdown")/${outputname%.*}.html + pandoc -s "$markdown" \ + --template="$TPL_PANDOC_PATH/default.html" \ + -o "$(dirname "$markdown")/${outputname%.*}.html" fi fi done diff --git a/functions/create-html-sections.sh b/functions/create-html-sections.sh @@ -6,56 +6,55 @@ create_html_sections () { get_pandoc_templates - for indexsubdir in $(find $CONTENT_PATH/ -mindepth 2 -name index.md -exec dirname {} \;); do + for indexsubdir in $(find "$CONTENT_PATH/" -mindepth 2 -name index.md -exec dirname {} \;); do # For each section page create a temporary "includes" folder - mkdir $indexsubdir/includes + mkdir "$indexsubdir/includes" if [[ " ${templates[*]} " == *" $(basename "$indexsubdir") "* ]]; then - tplname=$(basename "$indexsubdir") + tplname="$(basename "$indexsubdir")" else tplname=default fi # For all markdown files that are not "index.md" - for markdown in $(find $indexsubdir/ -type f \( -name "*.md" ! -name "index.md" \)); do + for markdown in $(find "$indexsubdir/" -type f \( -name "*.md" ! -name "index.md" \)); do # Markdown files names without path - outputname=$(basename "$markdown") + outputname="$(basename "$markdown")" # Parse the YAML block of the markdown - eval $(parse_yaml $markdown "config_") + eval "$(parse_yaml "$markdown" "config_")" # Set the variable for the date - markdown_date=$config_date - markdown_datetime=$config_datetime + markdown_date="$config_date$config_datetime" # Set the variable for the URL - url=$(find $PUBLICHTML/ -type f -name ${outputname%.*}.html;) + url=$(find "$PUBLICHTML/" -type f -name "${outputname%.*}".html;) # Create all the includes files that make up section page and put them into the "includes" folder - pandoc $markdown -s \ - --variable=url:$BASE_URL/${url#*/} \ - --template=$TPL_PANDOC_PATH/"$tplname"-index.inc.html \ + pandoc "$markdown" -s \ + --variable=url:"$BASE_URL/${url#*/}" \ + --template="$TPL_PANDOC_PATH/${tplname}-index.inc.html" \ -t html5 \ - -o $indexsubdir/includes/$markdown_date-$markdown_datetime-${outputname%.*}.inc.html + -o "$indexsubdir/includes/$markdown_date-${outputname%.*}".inc.html + + #echo ${tplname} done if test "$(ls -A "$indexsubdir/includes/")"; then # Sort all the includes files - sorted_includes=$(find $indexsubdir/includes/ -type f -name \*.inc.html | sort -nr) - # Create an HTML file with all the includes in descending order - pandoc -t html5 $sorted_includes \ - -o $indexsubdir/includes/includes.html \ + pandoc -t html5 $(find "$indexsubdir/includes/" -type f -name \*.inc.html | sort -nr) \ + -o "$indexsubdir/includes/includes.html" \ --parse-raw # Merge the "includes.html" and "index.md" to create the section page list - pandoc -t html5 $indexsubdir/index.md -s \ - --template=$TPL_PANDOC_PATH/"$tplname"-index.html \ - -A $indexsubdir/includes/includes.html \ - -o $indexsubdir/index.html + pandoc -t html5 "$indexsubdir/index.md" -s \ + --template="$TPL_PANDOC_PATH/${tplname}-index.html" \ + -A "$indexsubdir/includes/includes.html" \ + -o "$indexsubdir/index.html" # Remove the temporary "includes" folder and all his content - rm -Rf $indexsubdir/includes/ + rm -Rf "$indexsubdir/includes/" fi done diff --git a/functions/get-static-files.sh b/functions/get-static-files.sh @@ -4,5 +4,5 @@ get_static_files () { echo "- Rsync the static files into the public_html/ folder" - rsync -avmh $ASSETS_PATH/ $PUBLICHTML_PATH/ + rsync -avmh "$ASSETS_PATH/" "$PUBLICHTML_PATH/" } diff --git a/functions/move-html-to-publichtml.sh b/functions/move-html-to-publichtml.sh @@ -4,5 +4,5 @@ move_html_to_publichtml () { echo "- Rsync all HTML files and folders to the public_html/ folder" - rsync -avmh --include='*.html' -f 'hide,! */' $CONTENT_PATH/ $PUBLICHTML_PATH/ + rsync -avmh --include='*.html' -f 'hide,! */' "$CONTENT_PATH/" "$PUBLICHTML_PATH/" }