From 5ab5e6a4781c53aade17a9a98e123762691205c6 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 28 Dec 2020 21:34:30 +0100 Subject: Handle blog entry categories --- scripts/build_content.sh | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'scripts/build_content.sh') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index cf0128b..719b7c9 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -1,9 +1,13 @@ #!/bin/bash CONTENT_DIR="content/" +METADATA_DIR="metadata/" TEMPLATES_DIR="templates/" OUTPUT_DIR="output/" +CATEGORY_SHORT_LEN=3 +CATEGORY_MAP=$(cat "$METADATA_DIR/categories.json") + target_filename () { filename=$1 filename=${filename#"$CONTENT_DIR"} @@ -44,7 +48,7 @@ get_subpages_basedir() { echo "$filename" } -get_subpages() { +get_metadata() { basedir=$(get_subpages_basedir "$1") child_pages=() @@ -68,10 +72,12 @@ get_subpages() { if [ ${#child_pages[@]} -ne 0 ]; then #echo -e "\033[0;90m[////////]\033[0m Child pages:" - collected_metadata=$(echo "{ - \"all\": [], - \"by_year\": {} - }" | jq .) + pages=$(echo "{}" | jq ". + { \ + all: [], \ + by_year: {} \ + }") + + categories="{}" for file in "${child_pages[@]}"; do #echo -e "\033[0;90m[////////]\033[0m - $file" @@ -84,27 +90,41 @@ get_subpages() { -t plain \ --template scripts/metadata_tpl.json) - metadata=$(echo "$metadata" | jq ". + { url_rel: \"$url_rel\", url_abs: \"$url_abs\" }") + date=$(echo "$metadata" | jq -r .date) + category=$(echo "$metadata" | jq -r .category) + category_name=$(echo "$CATEGORY_MAP" | jq -r .$category) - collected_metadata=$(echo "$collected_metadata" | jq ".all += [ $metadata ]") + metadata=$(echo "$metadata" | jq ". + { \ + url_rel: \"$url_rel\", \ + url_abs: \"$url_abs\" \ + }") - date=$(echo "$metadata" | jq -r .date) + pages=$(echo "$pages" | jq ".all += [ $metadata ]") + + if [ "$category" != "" ]; then + categories=$(echo "$categories" | jq ". + { $category: \"$category_name\" }") + fi if [ "$date" != "" ]; then date_year=$(date -d "$date" +%Y) #date_month=$(date -d "$date" +%m) #date_day=$(date -d "$date" +%d) - collected_metadata=$(echo "$collected_metadata" | jq ".by_year.\"$date_year\" += [ $metadata ]") + pages=$(echo "$pages" | jq ".by_year.\"$date_year\" += [ $metadata ]") fi done - collected_metadata=$(echo "$collected_metadata" \ - | jq ".all |= (sort_by(.date) | reverse)" \ - | jq ".by_year[] |= (sort_by(.date) | reverse)" \ - | jq ".by_year |= (to_entries | sort_by(.key) | reverse)") + pages=$(echo "$pages" \ + | jq ".all |= (sort_by(.date) | reverse) \ + | .by_year |= (to_entries | sort_by(.key) | reverse \ + | .[].value |= (sort_by(.date) | reverse))") + + categories=$(echo "$categories" | jq ". | to_entries | sort_by(.key)") - echo "{ \"pages\": $collected_metadata }" | jq . + echo "{}" | jq ". + { \ + pages: $pages, \ + categories: $categories \ + }" fi } @@ -125,8 +145,8 @@ handle () { subpages_meta_file=$(mktemp) - # echo "$(get_subpages "$1")" - echo "$(get_subpages "$1")" > "$subpages_meta_file" + # echo "$(get_metadata "$1")" + echo "$(get_metadata "$1")" > "$subpages_meta_file" pandoc "$1" \ -f markdown \ -- cgit v1.2.3-70-g09d2