summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build_content.sh42
1 files changed, 22 insertions, 20 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh
index 4e1b396..fcabf9f 100755
--- a/scripts/build_content.sh
+++ b/scripts/build_content.sh
@@ -85,20 +85,14 @@ get_subpages_meta() {
85 child_pages=() 85 child_pages=()
86 86
87 if [ -d "$basedir" ]; then 87 if [ -d "$basedir" ]; then
88 mapfile -d $'\0' child_pages_1 < <(find $basedir/ \ 88 mapfile -d $'\0' child_pages < <(find "$basedir" \
89 -type f \
90 -name "*.md" ! -name "index.md" \
91 -maxdepth 1 \
92 -print0)
93
94 mapfile -d $'\0' child_pages_2 < <(find $basedir/ \
95 -type f \
96 -name "index.md" \
97 -mindepth 2 \
98 -maxdepth 2 \ 89 -maxdepth 2 \
90 -type f \
91 -name "*.md" \
92 ! -name "_*.md" \
93 ! -wholename "${basedir}index.md" \
94 \( -wholename "$basedir*/index.md" -o ! -wholename "$basedir*/*.md" \) \
99 -print0) 95 -print0)
100
101 child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}")
102 fi 96 fi
103 97
104 pages=$(echo "{}" | jq ". + { \ 98 pages=$(echo "{}" | jq ". + { \
@@ -115,7 +109,6 @@ get_subpages_meta() {
115 #echo -e "\033[0;90m[////////]\033[0m - $file" 109 #echo -e "\033[0;90m[////////]\033[0m - $file"
116 110
117 metadata=$(get_metadata "$file") 111 metadata=$(get_metadata "$file")
118 content=$(get_content "$file")
119 112
120 section=$(get_section "$file") 113 section=$(get_section "$file")
121 114
@@ -145,9 +138,11 @@ get_subpages_meta() {
145 category_name="" 138 category_name=""
146 139
147 if [ "$section" != "" ] && [ "$category" != "" ]; then 140 if [ "$section" != "" ] && [ "$category" != "" ]; then
148 category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) 141 category_name=$(echo "$CATEGORIES" | jq -r ".$section.$category")
149 fi 142 fi
150 143
144 content=$(get_content "$file")
145
151 metadata=$(echo "$metadata" | jq ". + { \ 146 metadata=$(echo "$metadata" | jq ". + { \
152 content: \"$(echo "$content" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\"/g')\", \ 147 content: \"$(echo "$content" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\"/g')\", \
153 date: { \ 148 date: { \
@@ -202,13 +197,11 @@ handle () {
202 if [ "${1#*.}" = "md" ]; then 197 if [ "${1#*.}" = "md" ]; then
203 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target_file" 198 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target_file"
204 199
205 meta_file=$(mktemp)
206
207 echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata" 200 echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata"
208 201
209 included_metadata=$(get_metadata "$1") 202 included_metadata=$(get_metadata "$1")
210 203
211 create_feed=$(echo "$included_metadata" | jq -r ".create_feed") 204 create_feed=$(echo "$included_metadata" | jq -r .create_feed)
212 205
213 url_abs=$(get_url_abs "$1" "html") 206 url_abs=$(get_url_abs "$1" "html")
214 url_full="${SITE%/}$url_abs" 207 url_full="${SITE%/}$url_abs"
@@ -248,6 +241,8 @@ handle () {
248 }") 241 }")
249 fi 242 fi
250 243
244 meta_file=$(mktemp)
245
251 echo "$added_metadata" > "$meta_file" 246 echo "$added_metadata" > "$meta_file"
252 247
253 if [ "$create_feed" = "true" ]; then 248 if [ "$create_feed" = "true" ]; then
@@ -291,6 +286,7 @@ handle () {
291if [ -z "$1" ]; then 286if [ -z "$1" ]; then
292 find "$CONTENT_DIR" \ 287 find "$CONTENT_DIR" \
293 -type f \ 288 -type f \
289 ! -name "_*.md" \
294 | while read file 290 | while read file
295 do 291 do
296 handle "$file" 292 handle "$file"
@@ -299,6 +295,7 @@ elif [ "$1" = "all_md" ]; then
299 find "$CONTENT_DIR" \ 295 find "$CONTENT_DIR" \
300 -type f \ 296 -type f \
301 -name "*.md" \ 297 -name "*.md" \
298 ! -name "_*.md" \
302 | while read file 299 | while read file
303 do 300 do
304 handle "$file" 301 handle "$file"
@@ -307,15 +304,20 @@ elif [ "$1" = "single" ]; then
307 if [ -z "$2" ]; then 304 if [ -z "$2" ]; then
308 echo -e "\033[0;31m[ERROR ]\033[0m \"single\" operation requires file argument" 305 echo -e "\033[0;31m[ERROR ]\033[0m \"single\" operation requires file argument"
309 else 306 else
310 handle "$2" 307 filename=$(basename "$2")
308 if [ "${filename:0:1}" != "_" ]; then
309 handle "$2"
310 fi
311 fi 311 fi
312elif [ "$1" = "delete" ]; then 312elif [ "$1" = "delete" ]; then
313 if [ -z "$2" ]; then 313 if [ -z "$2" ]; then
314 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" 314 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument"
315 else 315 else
316 target_file=$(get_target_filename "$2") 316 target_file=$(get_target_filename "$2")
317 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" 317 if [ -f "$target_file" ] || [ -d "$target_file" ]; then
318 rm -rf $target_file 318 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file"
319 rm -rf $target_file
320 fi
319 fi 321 fi
320else 322else
321 echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\"" 323 echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\""