From eb2ed3b2219f32e967ac5af3a62d4711d96ac7fd Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 30 Dec 2020 15:25:55 +0100 Subject: Improved build script output, metadata processing, and function names --- scripts/build_content.sh | 60 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 6250fe9..72e0956 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -25,7 +25,7 @@ FILTERS=$(get_filters) CATEGORIES=$(cat "$METADATA_DIR/categories.json") -target_filename() { +get_target_filename() { filename=$1 filename=${filename#"$CONTENT_DIR"} if [ "${filename##*.}" = "md" ]; then @@ -34,21 +34,23 @@ target_filename() { echo "$OUTPUT_DIR$filename" } -target_url_rel() { +get_url_rel() { basedir=$1 filename=$2 ext=$3 filename=$(realpath --relative-to="$basedir" "$filename") filename="${filename%.md}.$ext" - filename=${filename%index.html} + if [ "${filename##*/}" = "index.html" ]; then + filename=${filename%index.html} + fi echo "$filename" } -target_url_abs() { - echo "/$(target_url_rel "$CONTENT_DIR" "$1" "$2")" +get_url_abs() { + echo "/$(get_url_rel "$CONTENT_DIR" "$1" "$2")" } -metadata() { +get_metadata() { pandoc "$1" \ -f markdown \ -t plain \ @@ -67,7 +69,7 @@ get_subpages_basedir() { filename=$1 filename=${filename%.md} if [ "${filename##*/}" = "index" ]; then - filename=$(dirname "$filename") + filename=${filename%index} fi echo "$filename" } @@ -96,7 +98,6 @@ get_subpages_meta() { pages=$(echo "{}" | jq ". + { \ all: [], \ by_year: {}, \ - not_empty: false \ }") categories="{}" @@ -104,17 +105,15 @@ get_subpages_meta() { if [ ${#child_pages[@]} -ne 0 ]; then #echo -e "\033[0;90m[////////]\033[0m Child pages:" - pages=$(echo "$pages" | jq ".not_empty = true") - for file in "${child_pages[@]}"; do #echo -e "\033[0;90m[////////]\033[0m - $file" - metadata=$(metadata "$file") + metadata=$(get_metadata "$file") section=$(get_section "$file") - url_rel=$(target_url_rel "$basedir" "$file" "html") - url_abs=$(target_url_abs "$file" "html") + url_rel=$(get_url_rel "$basedir" "$file" "html") + url_abs=$(get_url_abs "$file" "html") url_full="${SITE%/}$url_abs" date=$(echo "$metadata" | jq -r .date) @@ -131,7 +130,7 @@ get_subpages_meta() { category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) fi - metadata=$(echo "$metadata" | jq ". * { \ + metadata=$(echo "$metadata" | jq ". + { \ date: { \ yyyy_mm_dd: \"$date\", \ rfc3339: \"$date_rfc3339\" \ @@ -173,7 +172,7 @@ get_subpages_meta() { } handle () { - target_file=$(target_filename "$1") + target_file=$(get_target_filename "$1") mkdir -p $(dirname "$target_file") @@ -182,13 +181,13 @@ handle () { meta_file=$(mktemp) - metadata=$(metadata "$1") - metadata=$(echo "[ \ - $metadata, \ - $(get_subpages_meta "$1") \ - ]" | jq ".[0] * .[1]") + echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata" + + metadata=$(get_metadata "$1") - url_abs=$(target_url_abs "$1" "html") + create_feed=$(echo "$metadata" | jq -r ".create_feed") + + url_abs=$(get_url_abs "$1" "html") url_full="${SITE%/}$url_abs" section=$(get_section "$1") @@ -198,7 +197,10 @@ handle () { is_home=true fi - metadata=$(echo "$metadata" | jq ". * { \ + metadata=$(echo "[ \ + $metadata, \ + $(get_subpages_meta "$1") \ + ]" | jq ".[0] + .[1] + { \ url: { \ abs: \"$url_abs\", \ full: \"$url_full\" \ @@ -210,14 +212,12 @@ handle () { is_home: $is_home \ }") - create_feed=$(echo "$metadata" | jq -r ".create_feed") - if [ "$create_feed" = "true" ]; then - feed_url_abs="$(target_url_abs "$1" "xml")" + feed_url_abs="$(get_url_abs "$1" "xml")" feed_url_full="${SITE%/}$feed_url_abs" last_update=$(echo "$metadata" | jq -r ".pages.all[0].date") - metadata=$(echo "$metadata" | jq ". * { \ + metadata=$(echo "$metadata" | jq ". + { \ feed: { \ last_update: $last_update, \ url: { \ @@ -231,6 +231,8 @@ handle () { echo "$metadata" > "$meta_file" if [ "$create_feed" = "true" ]; then + echo -e "\033[0;90m[COMPILE ]\033[0m Creating feed" + pandoc "$1" \ -f markdown \ -t html5 \ @@ -241,6 +243,8 @@ handle () { $FILTERS fi + echo -e "\033[0;90m[COMPILE ]\033[0m Creating page" + pandoc "$1" \ -f markdown \ -t html5 \ @@ -255,6 +259,8 @@ handle () { # echo $(pandoc "$1" \ # -f markdown \ # -t json) + + echo -e "\033[0;90m[COMPILE ]\033[0m Done" else echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target_file" @@ -287,7 +293,7 @@ elif [ "$1" = "delete" ]; then if [ -z "$2" ]; then echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" else - target_file=$(target_filename "$2") + target_file=$(get_target_filename "$2") echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" rm -rf $target_file fi -- cgit v1.2.3-70-g09d2