From 3ab8981195dbbdc553fbe1a14178b6793a81fa3b Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 30 Dec 2020 09:06:31 +0100 Subject: Revert to old category metadata collection, add support for authors --- scripts/build_content.sh | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'scripts/build_content.sh') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 12de8c8..fc5ddea 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -25,6 +25,8 @@ get_filters() { FILTERS=$(get_filters) +CATEGORIES=$(cat "$METADATA_DIR/categories.json") + target_filename() { filename=$1 filename=${filename#"$CONTENT_DIR"} @@ -98,6 +100,8 @@ get_subpages_meta() { not_empty: false \ }") + categories="{}" + if [ ${#child_pages[@]} -ne 0 ]; then #echo -e "\033[0;90m[////////]\033[0m Child pages:" @@ -108,6 +112,8 @@ get_subpages_meta() { metadata=$(metadata "$file") + section=$(get_section "$file") + url_rel=$(target_url_rel "$basedir" "$file" "html") url_abs=$(target_url_abs "$file" "html") url_full="${SITE%/}$url_abs" @@ -119,6 +125,13 @@ get_subpages_meta() { date_rfc3339=$(date -d "$date" --rfc-3339=seconds | sed 's/ /T/') fi + category=$(echo "$metadata" | jq -r .category) + category_name="" + + if [ "$section" != "" ] && [ "$category" != "" ]; then + category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) + fi + metadata=$(echo "$metadata" | jq ". * { \ date: { \ yyyy_mm_dd: \"$date\", \ @@ -140,16 +153,23 @@ get_subpages_meta() { pages=$(echo "$pages" | jq ".by_year.\"$date_year\" += [ $metadata ]") fi - done - pages=$(echo "$pages" \ - | jq ".all |= (sort_by(.date) | reverse) \ - | .by_year |= (to_entries | sort_by(.key) | reverse \ - | .[].value |= (sort_by(.date) | reverse))") + if [ "$category" != "" ]; then + categories=$(echo "$categories" | jq ".$category = { name: \"$category_name\", count: (.$category.count + 1) } ") + fi + done fi + 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 "{}" | jq ". + { \ - pages: $pages \ + pages: $pages, \ + categories: $categories }" } @@ -163,7 +183,7 @@ handle () { meta_file=$(mktemp) - metadata=$(metadata "$file") + metadata=$(metadata "$1") metadata=$(echo "[ \ $metadata, \ $(get_subpages_meta "$1") \ -- cgit v1.2.3-70-g09d2