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 --- metadata/categories.json | 6 ++++++ metadata/metadata.yaml | 8 +++----- scripts/build_content.sh | 34 +++++++++++++++++++++++++++------- templates/base.html | 6 +++--- templates/categoryRef.html | 6 +++--- templates/feed.xml | 27 +++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 metadata/categories.json diff --git a/metadata/categories.json b/metadata/categories.json new file mode 100644 index 0000000..9ce0815 --- /dev/null +++ b/metadata/categories.json @@ -0,0 +1,6 @@ +{ + "blog": { + "tes": "Testing", + "per": "Personal" + } +} diff --git a/metadata/metadata.yaml b/metadata/metadata.yaml index 00a8571..7d30a2a 100644 --- a/metadata/metadata.yaml +++ b/metadata/metadata.yaml @@ -2,6 +2,9 @@ site: title: Volpeon's Den logo: \\\\/ +author: + - name: Volpeon + menus: main: - id: index @@ -10,8 +13,3 @@ menus: - id: blog label: Blog url: /blog/ - -categories: - blog: - tes: Testing - per: Personal 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") \ diff --git a/templates/base.html b/templates/base.html index 9574d08..4b8ea1e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,8 +6,8 @@ - $for(author-meta)$ - + $for(author)$ + $endfor$ $if(date-meta)$ @@ -53,7 +53,7 @@ $body$ $if(section.is_blog)$ $if(pages.not_empty)$ - ${categories.blog:categoryRef()} + ${categoryRef()} ${pagelistByYear()} $endif$ $endif$ diff --git a/templates/categoryRef.html b/templates/categoryRef.html index 5715fa8..58dc5fe 100644 --- a/templates/categoryRef.html +++ b/templates/categoryRef.html @@ -1,7 +1,7 @@ -$if(it)$ +$if(categories)$ $endif$ diff --git a/templates/feed.xml b/templates/feed.xml index 68d2fc4..f1439eb 100644 --- a/templates/feed.xml +++ b/templates/feed.xml @@ -5,6 +5,14 @@ $feed.last_update.rfc3339$ $url.full$ + $for(author)$ + + $it.name$ + $if(it.email)$ + $it.email$ + $endif$ + + $endfor$ $for(pages)$ $for(it.all)$ @@ -12,6 +20,25 @@ $it.url.full$ <![CDATA[$it.title$]]> + $if(it.author)$ + $for(it.author)$ + + $it.name$ + $if(it.email)$ + $it.email$ + $endif$ + + $endfor$ + $else$ + $for(author)$ + + $author.name$ + $if(author.email)$ + $author.email$ + $endif$ + + $endfor$ + $endif$ $it.date.rfc3339$ $it.date.rfc3339$ -- cgit v1.2.3-70-g09d2