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 --- assets/css/_basics.scss | 2 +- assets/css/components/_hlist.scss | 13 ++++++++++ assets/css/components/_spacer.scss | 5 ++++ assets/css/style.scss | 2 ++ content/blog/test1.md | 1 + content/blog/test2/index.md | 1 + content/projects/index.md | 5 ---- metadata/categories.json | 4 +++ metadata/metadata.yaml | 3 --- scripts/build_content.sh | 52 ++++++++++++++++++++++++++------------ scripts/metadata_tpl.json | 3 ++- templates/base.html | 1 + templates/categoryRef.html | 7 +++++ templates/pagelistByYear.html | 4 ++- 14 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 assets/css/components/_hlist.scss create mode 100644 assets/css/components/_spacer.scss delete mode 100644 content/projects/index.md create mode 100644 metadata/categories.json create mode 100644 templates/categoryRef.html diff --git a/assets/css/_basics.scss b/assets/css/_basics.scss index a8ed013..2b0d0a6 100644 --- a/assets/css/_basics.scss +++ b/assets/css/_basics.scss @@ -144,7 +144,7 @@ p { hr { height: 1px; - margin: ($line-height * 2em) 0 ($line-height * 2em); + margin: ($line-height * 2em) 0; border: 0; background-color: var(--obj); } diff --git a/assets/css/components/_hlist.scss b/assets/css/components/_hlist.scss new file mode 100644 index 0000000..a7cf665 --- /dev/null +++ b/assets/css/components/_hlist.scss @@ -0,0 +1,13 @@ +.c-hlist { + display: flex; + + &__item { + display: block; + margin-right: 4ch; + padding-left: 0; + + &::before { + display: none; + } + } +} diff --git a/assets/css/components/_spacer.scss b/assets/css/components/_spacer.scss new file mode 100644 index 0000000..692eb29 --- /dev/null +++ b/assets/css/components/_spacer.scss @@ -0,0 +1,5 @@ +.c-spacer { + display: block; + height: 0; + margin: ($line-height * 2em) 0 0; +} diff --git a/assets/css/style.scss b/assets/css/style.scss index 8d9a87f..90c1bfc 100644 --- a/assets/css/style.scss +++ b/assets/css/style.scss @@ -2,6 +2,8 @@ @import 'functions'; @import 'basics'; +@import 'components/spacer'; +@import 'components/hlist'; @import 'components/nav'; @import 'components/page-header'; diff --git a/content/blog/test1.md b/content/blog/test1.md index 8e2b0b9..05c2b2d 100644 --- a/content/blog/test1.md +++ b/content/blog/test1.md @@ -1,6 +1,7 @@ --- date: 2020-12-25 title: Test Page 1 +category: tes --- # Test Page 1 diff --git a/content/blog/test2/index.md b/content/blog/test2/index.md index 70130d1..9d1ebd2 100644 --- a/content/blog/test2/index.md +++ b/content/blog/test2/index.md @@ -1,6 +1,7 @@ --- date: 2020-12-21 title: Test Page 2 +category: per --- # Test Page 2 diff --git a/content/projects/index.md b/content/projects/index.md deleted file mode 100644 index fd5a713..0000000 --- a/content/projects/index.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Projects ---- - -# Projects diff --git a/metadata/categories.json b/metadata/categories.json new file mode 100644 index 0000000..b0c5f84 --- /dev/null +++ b/metadata/categories.json @@ -0,0 +1,4 @@ +{ + "tes": "Testing", + "per": "Personal" +} diff --git a/metadata/metadata.yaml b/metadata/metadata.yaml index eb0f054..d2d4b1f 100644 --- a/metadata/metadata.yaml +++ b/metadata/metadata.yaml @@ -10,6 +10,3 @@ menus: - id: blog label: Blog url: /blog/ - - id: projects - label: Projects - url: /projects/ 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 \ diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json index eeda341..76e4439 100644 --- a/scripts/metadata_tpl.json +++ b/scripts/metadata_tpl.json @@ -1,4 +1,5 @@ { "title": "$title$", - "date": "$date$" + "date": "$date$", + "category": "$category$" } diff --git a/templates/base.html b/templates/base.html index 8d10d13..330e759 100644 --- a/templates/base.html +++ b/templates/base.html @@ -49,6 +49,7 @@ ${pageHeader()} $body$ $if(isblog)$ + ${categoryRef()} ${pagelistByYear()} $endif$ diff --git a/templates/categoryRef.html b/templates/categoryRef.html new file mode 100644 index 0000000..9a363cf --- /dev/null +++ b/templates/categoryRef.html @@ -0,0 +1,7 @@ +$if(categories)$ + +$endif$ diff --git a/templates/pagelistByYear.html b/templates/pagelistByYear.html index 972bacc..20ce6c4 100644 --- a/templates/pagelistByYear.html +++ b/templates/pagelistByYear.html @@ -1,9 +1,11 @@ $for(pages)$ $for(it.by_year)$ +$--
+$--

$it.key$

-- cgit v1.2.3-70-g09d2