diff options
author | Volpeon <git@volpeon.ink> | 2020-12-30 15:25:55 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2020-12-30 15:25:55 +0100 |
commit | eb2ed3b2219f32e967ac5af3a62d4711d96ac7fd (patch) | |
tree | 72301782272f6e4df870b7f27cbe526743db7f3b /scripts | |
parent | Store list of feeds in metadata file (diff) | |
download | volpeon.ink-eb2ed3b2219f32e967ac5af3a62d4711d96ac7fd.tar.gz volpeon.ink-eb2ed3b2219f32e967ac5af3a62d4711d96ac7fd.tar.bz2 volpeon.ink-eb2ed3b2219f32e967ac5af3a62d4711d96ac7fd.zip |
Improved build script output, metadata processing, and function names
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build_content.sh | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 6250fe9..72e0956 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh | |||
@@ -25,7 +25,7 @@ FILTERS=$(get_filters) | |||
25 | 25 | ||
26 | CATEGORIES=$(cat "$METADATA_DIR/categories.json") | 26 | CATEGORIES=$(cat "$METADATA_DIR/categories.json") |
27 | 27 | ||
28 | target_filename() { | 28 | get_target_filename() { |
29 | filename=$1 | 29 | filename=$1 |
30 | filename=${filename#"$CONTENT_DIR"} | 30 | filename=${filename#"$CONTENT_DIR"} |
31 | if [ "${filename##*.}" = "md" ]; then | 31 | if [ "${filename##*.}" = "md" ]; then |
@@ -34,21 +34,23 @@ target_filename() { | |||
34 | echo "$OUTPUT_DIR$filename" | 34 | echo "$OUTPUT_DIR$filename" |
35 | } | 35 | } |
36 | 36 | ||
37 | target_url_rel() { | 37 | get_url_rel() { |
38 | basedir=$1 | 38 | basedir=$1 |
39 | filename=$2 | 39 | filename=$2 |
40 | ext=$3 | 40 | ext=$3 |
41 | filename=$(realpath --relative-to="$basedir" "$filename") | 41 | filename=$(realpath --relative-to="$basedir" "$filename") |
42 | filename="${filename%.md}.$ext" | 42 | filename="${filename%.md}.$ext" |
43 | filename=${filename%index.html} | 43 | if [ "${filename##*/}" = "index.html" ]; then |
44 | filename=${filename%index.html} | ||
45 | fi | ||
44 | echo "$filename" | 46 | echo "$filename" |
45 | } | 47 | } |
46 | 48 | ||
47 | target_url_abs() { | 49 | get_url_abs() { |
48 | echo "/$(target_url_rel "$CONTENT_DIR" "$1" "$2")" | 50 | echo "/$(get_url_rel "$CONTENT_DIR" "$1" "$2")" |
49 | } | 51 | } |
50 | 52 | ||
51 | metadata() { | 53 | get_metadata() { |
52 | pandoc "$1" \ | 54 | pandoc "$1" \ |
53 | -f markdown \ | 55 | -f markdown \ |
54 | -t plain \ | 56 | -t plain \ |
@@ -67,7 +69,7 @@ get_subpages_basedir() { | |||
67 | filename=$1 | 69 | filename=$1 |
68 | filename=${filename%.md} | 70 | filename=${filename%.md} |
69 | if [ "${filename##*/}" = "index" ]; then | 71 | if [ "${filename##*/}" = "index" ]; then |
70 | filename=$(dirname "$filename") | 72 | filename=${filename%index} |
71 | fi | 73 | fi |
72 | echo "$filename" | 74 | echo "$filename" |
73 | } | 75 | } |
@@ -96,7 +98,6 @@ get_subpages_meta() { | |||
96 | pages=$(echo "{}" | jq ". + { \ | 98 | pages=$(echo "{}" | jq ". + { \ |
97 | all: [], \ | 99 | all: [], \ |
98 | by_year: {}, \ | 100 | by_year: {}, \ |
99 | not_empty: false \ | ||
100 | }") | 101 | }") |
101 | 102 | ||
102 | categories="{}" | 103 | categories="{}" |
@@ -104,17 +105,15 @@ get_subpages_meta() { | |||
104 | if [ ${#child_pages[@]} -ne 0 ]; then | 105 | if [ ${#child_pages[@]} -ne 0 ]; then |
105 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" | 106 | #echo -e "\033[0;90m[////////]\033[0m Child pages:" |
106 | 107 | ||
107 | pages=$(echo "$pages" | jq ".not_empty = true") | ||
108 | |||
109 | for file in "${child_pages[@]}"; do | 108 | for file in "${child_pages[@]}"; do |
110 | #echo -e "\033[0;90m[////////]\033[0m - $file" | 109 | #echo -e "\033[0;90m[////////]\033[0m - $file" |
111 | 110 | ||
112 | metadata=$(metadata "$file") | 111 | metadata=$(get_metadata "$file") |
113 | 112 | ||
114 | section=$(get_section "$file") | 113 | section=$(get_section "$file") |
115 | 114 | ||
116 | url_rel=$(target_url_rel "$basedir" "$file" "html") | 115 | url_rel=$(get_url_rel "$basedir" "$file" "html") |
117 | url_abs=$(target_url_abs "$file" "html") | 116 | url_abs=$(get_url_abs "$file" "html") |
118 | url_full="${SITE%/}$url_abs" | 117 | url_full="${SITE%/}$url_abs" |
119 | 118 | ||
120 | date=$(echo "$metadata" | jq -r .date) | 119 | date=$(echo "$metadata" | jq -r .date) |
@@ -131,7 +130,7 @@ get_subpages_meta() { | |||
131 | category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) | 130 | category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) |
132 | fi | 131 | fi |
133 | 132 | ||
134 | metadata=$(echo "$metadata" | jq ". * { \ | 133 | metadata=$(echo "$metadata" | jq ". + { \ |
135 | date: { \ | 134 | date: { \ |
136 | yyyy_mm_dd: \"$date\", \ | 135 | yyyy_mm_dd: \"$date\", \ |
137 | rfc3339: \"$date_rfc3339\" \ | 136 | rfc3339: \"$date_rfc3339\" \ |
@@ -173,7 +172,7 @@ get_subpages_meta() { | |||
173 | } | 172 | } |
174 | 173 | ||
175 | handle () { | 174 | handle () { |
176 | target_file=$(target_filename "$1") | 175 | target_file=$(get_target_filename "$1") |
177 | 176 | ||
178 | mkdir -p $(dirname "$target_file") | 177 | mkdir -p $(dirname "$target_file") |
179 | 178 | ||
@@ -182,13 +181,13 @@ handle () { | |||
182 | 181 | ||
183 | meta_file=$(mktemp) | 182 | meta_file=$(mktemp) |
184 | 183 | ||
185 | metadata=$(metadata "$1") | 184 | echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata" |
186 | metadata=$(echo "[ \ | 185 | |
187 | $metadata, \ | 186 | metadata=$(get_metadata "$1") |
188 | $(get_subpages_meta "$1") \ | ||
189 | ]" | jq ".[0] * .[1]") | ||
190 | 187 | ||
191 | url_abs=$(target_url_abs "$1" "html") | 188 | create_feed=$(echo "$metadata" | jq -r ".create_feed") |
189 | |||
190 | url_abs=$(get_url_abs "$1" "html") | ||
192 | url_full="${SITE%/}$url_abs" | 191 | url_full="${SITE%/}$url_abs" |
193 | 192 | ||
194 | section=$(get_section "$1") | 193 | section=$(get_section "$1") |
@@ -198,7 +197,10 @@ handle () { | |||
198 | is_home=true | 197 | is_home=true |
199 | fi | 198 | fi |
200 | 199 | ||
201 | metadata=$(echo "$metadata" | jq ". * { \ | 200 | metadata=$(echo "[ \ |
201 | $metadata, \ | ||
202 | $(get_subpages_meta "$1") \ | ||
203 | ]" | jq ".[0] + .[1] + { \ | ||
202 | url: { \ | 204 | url: { \ |
203 | abs: \"$url_abs\", \ | 205 | abs: \"$url_abs\", \ |
204 | full: \"$url_full\" \ | 206 | full: \"$url_full\" \ |
@@ -210,14 +212,12 @@ handle () { | |||
210 | is_home: $is_home \ | 212 | is_home: $is_home \ |
211 | }") | 213 | }") |
212 | 214 | ||
213 | create_feed=$(echo "$metadata" | jq -r ".create_feed") | ||
214 | |||
215 | if [ "$create_feed" = "true" ]; then | 215 | if [ "$create_feed" = "true" ]; then |
216 | feed_url_abs="$(target_url_abs "$1" "xml")" | 216 | feed_url_abs="$(get_url_abs "$1" "xml")" |
217 | feed_url_full="${SITE%/}$feed_url_abs" | 217 | feed_url_full="${SITE%/}$feed_url_abs" |
218 | last_update=$(echo "$metadata" | jq -r ".pages.all[0].date") | 218 | last_update=$(echo "$metadata" | jq -r ".pages.all[0].date") |
219 | 219 | ||
220 | metadata=$(echo "$metadata" | jq ". * { \ | 220 | metadata=$(echo "$metadata" | jq ". + { \ |
221 | feed: { \ | 221 | feed: { \ |
222 | last_update: $last_update, \ | 222 | last_update: $last_update, \ |
223 | url: { \ | 223 | url: { \ |
@@ -231,6 +231,8 @@ handle () { | |||
231 | echo "$metadata" > "$meta_file" | 231 | echo "$metadata" > "$meta_file" |
232 | 232 | ||
233 | if [ "$create_feed" = "true" ]; then | 233 | if [ "$create_feed" = "true" ]; then |
234 | echo -e "\033[0;90m[COMPILE ]\033[0m Creating feed" | ||
235 | |||
234 | pandoc "$1" \ | 236 | pandoc "$1" \ |
235 | -f markdown \ | 237 | -f markdown \ |
236 | -t html5 \ | 238 | -t html5 \ |
@@ -241,6 +243,8 @@ handle () { | |||
241 | $FILTERS | 243 | $FILTERS |
242 | fi | 244 | fi |
243 | 245 | ||
246 | echo -e "\033[0;90m[COMPILE ]\033[0m Creating page" | ||
247 | |||
244 | pandoc "$1" \ | 248 | pandoc "$1" \ |
245 | -f markdown \ | 249 | -f markdown \ |
246 | -t html5 \ | 250 | -t html5 \ |
@@ -255,6 +259,8 @@ handle () { | |||
255 | # echo $(pandoc "$1" \ | 259 | # echo $(pandoc "$1" \ |
256 | # -f markdown \ | 260 | # -f markdown \ |
257 | # -t json) | 261 | # -t json) |
262 | |||
263 | echo -e "\033[0;90m[COMPILE ]\033[0m Done" | ||
258 | else | 264 | else |
259 | echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target_file" | 265 | echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target_file" |
260 | 266 | ||
@@ -287,7 +293,7 @@ elif [ "$1" = "delete" ]; then | |||
287 | if [ -z "$2" ]; then | 293 | if [ -z "$2" ]; then |
288 | echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" | 294 | echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" |
289 | else | 295 | else |
290 | target_file=$(target_filename "$2") | 296 | target_file=$(get_target_filename "$2") |
291 | echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" | 297 | echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" |
292 | rm -rf $target_file | 298 | rm -rf $target_file |
293 | fi | 299 | fi |