From afaa48b03c8d9dcbc7bbce47b94ec6bdd2da3502 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 26 Dec 2020 23:37:48 +0100 Subject: Improved CSS variable names, improved script variable names, added initial support for finding child pages --- scripts/build_content.sh | 74 ++++++++++++++++++++++++++++++++++++++-------- scripts/watch_content.sh | 10 +++---- scripts/watch_metadata.sh | 2 +- scripts/watch_sass.sh | 2 +- scripts/watch_templates.sh | 2 +- 5 files changed, 69 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 6b50cd8..1344be1 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -1,6 +1,6 @@ #!/bin/bash -target () { +target_filename () { if [ "${1#*.}" = "md" ]; then echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)" else @@ -8,40 +8,88 @@ target () { fi } +get_subpages_basedir() { + filename=$(basename "$1") + if [ "$filename" = "index.md" ]; then + dirname "$1" + else + echo "${1%.md}" + fi +} + +get_subpages() { + basedir=$(get_subpages_basedir "$1") + child_pages=() + + if [ -d "$basedir" ]; then + mapfile -d $'\0' child_pages_1 < <(find $basedir/ \ + -type f \ + -name "*.md" ! -name "index.md" \ + -maxdepth 1 \ + -print0) + + mapfile -d $'\0' child_pages_2 < <(find $basedir/ \ + -type f \ + -name "index.md" \ + -mindepth 2 \ + -maxdepth 2 \ + -print0) + + child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}") + fi + + if [ ${#child_pages[@]} -ne 0 ]; then + echo -e "\033[0;90m[////////]\033[0m Child pages:" + + for file in "${child_pages[@]}"; do + echo -e "\033[0;90m[////////]\033[0m - $file" + done + fi +} + handle () { - TARGET=$(target "$1") - mkdir -p $(dirname "$TARGET") + target=$(target_filename "$1") + mkdir -p $(dirname "$target") if [ "${1#*.}" = "md" ]; then - echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $TARGET" + echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target" + + subpages_meta=$(mktemp) + + # $(get_subpages "$1") > "$subpages_meta" + + get_subpages "$1" pandoc "$1" \ -f markdown \ -t html5 \ --template templates/base.html \ - -o "$TARGET" \ - --metadata-file metadata/metadata.json + -o "$target" \ + --metadata-file metadata/metadata.yaml \ + --metadata-file "$subpages_meta" + + rm "$subpages_meta" else - echo -e "\033[0;32m[COPY ]\033[0m $1 -> $TARGET" + echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target" - cp "$1" "$TARGET" + cp "$1" "$target" fi } if [ -z "$1" ]; then find content/ \ -type f \ - | while read FILE + | while read file do - handle "$FILE" + handle "$file" done elif [ "$1" = "all_md" ]; then find content/ \ -type f \ -name "*.md" \ - | while read FILE + | while read file do - handle "$FILE" + handle "$file" done elif [ "$1" = "single" ]; then if [ -z "$2" ]; then @@ -53,7 +101,7 @@ elif [ "$1" = "delete" ]; then if [ -z "$2" ]; then echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" else - TARGET=$(target "$2") + TARGET=$(target_filename "$2") echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $TARGET" rm -rf $TARGET fi diff --git a/scripts/watch_content.sh b/scripts/watch_content.sh index 769f2c5..f0d1b42 100755 --- a/scripts/watch_content.sh +++ b/scripts/watch_content.sh @@ -1,11 +1,11 @@ #!/bin/bash inotifywait -qrme close_write,delete,move --format "%w%f" content \ - | while read FILENAME + | while read file do - if [ -f "$FILENAME" ]; then - scripts/build_content.sh "single" "$FILENAME" - elif [ ! -d "$FILENAME" ]; then - scripts/build_content.sh "delete" "$FILENAME" + if [ -f "$file" ]; then + scripts/build_content.sh "single" "$file" + elif [ ! -d "$file" ]; then + scripts/build_content.sh "delete" "$file" fi done diff --git a/scripts/watch_metadata.sh b/scripts/watch_metadata.sh index 41457e1..780177e 100755 --- a/scripts/watch_metadata.sh +++ b/scripts/watch_metadata.sh @@ -1,7 +1,7 @@ #!/bin/bash inotifywait -qrme close_write,delete,move --format "%w%f" metadata \ - | while read FILENAME + | while read file do scripts/build_content.sh "all_md" done diff --git a/scripts/watch_sass.sh b/scripts/watch_sass.sh index a5649e7..d451135 100755 --- a/scripts/watch_sass.sh +++ b/scripts/watch_sass.sh @@ -1,7 +1,7 @@ #!/bin/bash inotifywait -qrme close_write,delete,move --format "%w%f" assets \ - | while read FILENAME + | while read file do scripts/build_sass.sh done diff --git a/scripts/watch_templates.sh b/scripts/watch_templates.sh index 3482ac6..9b464d4 100755 --- a/scripts/watch_templates.sh +++ b/scripts/watch_templates.sh @@ -1,7 +1,7 @@ #!/bin/bash inotifywait -qrme close_write,delete,move --format "%w%f" templates \ - | while read FILENAME + | while read file do scripts/build_content.sh "all_md" done -- cgit v1.2.3-70-g09d2