diff options
author | Volpeon <git@volpeon.ink> | 2020-12-28 21:34:30 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2020-12-28 21:34:30 +0100 |
commit | 5ab5e6a4781c53aade17a9a98e123762691205c6 (patch) | |
tree | c8a1eed27676e2118a8a44270a9ffa82e9e98b13 /scripts | |
parent | Export pages grouped by year as array instead of object (diff) | |
download | volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.tar.gz volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.tar.bz2 volpeon.ink-5ab5e6a4781c53aade17a9a98e123762691205c6.zip |
Handle blog entry categories
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build_content.sh | 52 | ||||
-rw-r--r-- | scripts/metadata_tpl.json | 3 |
2 files changed, 38 insertions, 17 deletions
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 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CONTENT_DIR="content/" | 3 | CONTENT_DIR="content/" |
4 | METADATA_DIR="metadata/" | ||
4 | TEMPLATES_DIR="templates/" | 5 | TEMPLATES_DIR="templates/" |
5 | OUTPUT_DIR="output/" | 6 | OUTPUT_DIR="output/" |
6 | 7 | ||
8 | CATEGORY_SHORT_LEN=3 | ||
9 | CATEGORY_MAP=$(cat "$METADATA_DIR/categories.json") | ||
10 | |||
7 | target_filename () { | 11 | target_filename () { |
8 | filename=$1 | 12 | filename=$1 |
9 | filename=${filename#"$CONTENT_DIR"} | 13 | filename=${filename#"$CONTENT_DIR"} |
@@ -44,7 +48,7 @@ get_subpages_basedir() { | |||
44 | echo "$filename" | 48 | echo "$filename" |
45 | } | 49 | } |
46 | 50 | ||
47 | get_subpages() { | 51 | get_metadata() { |
48 | basedir=$(get_subpages_basedir "$1") | 52 | basedir=$(get_subpages_basedir "$1") |
49 | child_pages=() | 53 | child_pages=() |
50 | 54 | ||
@@ -68,10 +72,12 @@ get_subpages() { | |||
68 | if [ ${#child_pages[@]} -ne 0 ]; then | 72 | if [ ${#child_pages[@]} -ne 0 ]; then |
69 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" | 73 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" |
70 | 74 | ||
71 | collected_metadata=$(echo "{ | 75 | pages=$(echo "{}" | jq ". + { \ |
72 | \"all\": [], | 76 | all: [], \ |
73 | \"by_year\": {} | 77 | by_year: {} \ |
74 | }" | jq .) | 78 | }") |
79 | |||
80 | categories="{}" | ||
75 | 81 | ||
76 | for file in "${child_pages[@]}"; do | 82 | for file in "${child_pages[@]}"; do |
77 | #echo -e "\033[0;90m[////////]\033[0m - $file" | 83 | #echo -e "\033[0;90m[////////]\033[0m - $file" |
@@ -84,27 +90,41 @@ get_subpages() { | |||
84 | -t plain \ | 90 | -t plain \ |
85 | --template scripts/metadata_tpl.json) | 91 | --template scripts/metadata_tpl.json) |
86 | 92 | ||
87 | metadata=$(echo "$metadata" | jq ". + { url_rel: \"$url_rel\", url_abs: \"$url_abs\" }") | 93 | date=$(echo "$metadata" | jq -r .date) |
94 | category=$(echo "$metadata" | jq -r .category) | ||
95 | category_name=$(echo "$CATEGORY_MAP" | jq -r .$category) | ||
88 | 96 | ||
89 | collected_metadata=$(echo "$collected_metadata" | jq ".all += [ $metadata ]") | 97 | metadata=$(echo "$metadata" | jq ". + { \ |
98 | url_rel: \"$url_rel\", \ | ||
99 | url_abs: \"$url_abs\" \ | ||
100 | }") | ||
90 | 101 | ||
91 | date=$(echo "$metadata" | jq -r .date) | 102 | pages=$(echo "$pages" | jq ".all += [ $metadata ]") |
103 | |||
104 | if [ "$category" != "" ]; then | ||
105 | categories=$(echo "$categories" | jq ". + { $category: \"$category_name\" }") | ||
106 | fi | ||
92 | 107 | ||
93 | if [ "$date" != "" ]; then | 108 | if [ "$date" != "" ]; then |
94 | date_year=$(date -d "$date" +%Y) | 109 | date_year=$(date -d "$date" +%Y) |
95 | #date_month=$(date -d "$date" +%m) | 110 | #date_month=$(date -d "$date" +%m) |
96 | #date_day=$(date -d "$date" +%d) | 111 | #date_day=$(date -d "$date" +%d) |
97 | 112 | ||
98 | collected_metadata=$(echo "$collected_metadata" | jq ".by_year.\"$date_year\" += [ $metadata ]") | 113 | pages=$(echo "$pages" | jq ".by_year.\"$date_year\" += [ $metadata ]") |
99 | fi | 114 | fi |
100 | done | 115 | done |
101 | 116 | ||
102 | collected_metadata=$(echo "$collected_metadata" \ | 117 | pages=$(echo "$pages" \ |
103 | | jq ".all |= (sort_by(.date) | reverse)" \ | 118 | | jq ".all |= (sort_by(.date) | reverse) \ |
104 | | jq ".by_year[] |= (sort_by(.date) | reverse)" \ | 119 | | .by_year |= (to_entries | sort_by(.key) | reverse \ |
105 | | jq ".by_year |= (to_entries | sort_by(.key) | reverse)") | 120 | | .[].value |= (sort_by(.date) | reverse))") |
121 | |||
122 | categories=$(echo "$categories" | jq ". | to_entries | sort_by(.key)") | ||
106 | 123 | ||
107 | echo "{ \"pages\": $collected_metadata }" | jq . | 124 | echo "{}" | jq ". + { \ |
125 | pages: $pages, \ | ||
126 | categories: $categories \ | ||
127 | }" | ||
108 | fi | 128 | fi |
109 | } | 129 | } |
110 | 130 | ||
@@ -125,8 +145,8 @@ handle () { | |||
125 | 145 | ||
126 | subpages_meta_file=$(mktemp) | 146 | subpages_meta_file=$(mktemp) |
127 | 147 | ||
128 | # echo "$(get_subpages "$1")" | 148 | # echo "$(get_metadata "$1")" |
129 | echo "$(get_subpages "$1")" > "$subpages_meta_file" | 149 | echo "$(get_metadata "$1")" > "$subpages_meta_file" |
130 | 150 | ||
131 | pandoc "$1" \ | 151 | pandoc "$1" \ |
132 | -f markdown \ | 152 | -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 @@ | |||
1 | { | 1 | { |
2 | "title": "$title$", | 2 | "title": "$title$", |
3 | "date": "$date$" | 3 | "date": "$date$", |
4 | "category": "$category$" | ||
4 | } | 5 | } |