From abe8e1b0a6050c61f97eebdcd5b54d120ac591ac Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 27 Dec 2020 11:24:38 +0100 Subject: Build script: Improved path and relative link calculation, added vars to configure input and output dir --- scripts/build_content.sh | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 1344be1..b7d0c24 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -1,20 +1,34 @@ #!/bin/bash +CONTENT_DIR="content/" +OUTPUT_DIR="output/" + target_filename () { - if [ "${1#*.}" = "md" ]; then - echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)" - else - echo "output/$(echo "$1" | cut -sd / -f 2-)" + filename=$1 + filename=${filename#"$CONTENT_DIR"} + if [ "${filename##*.}" = "md" ]; then + filename="${filename%.md}.html" fi + echo "$OUTPUT_DIR$filename" +} + +target_url_rel () { + basedir=$1 + filename=$2 + filename=$(realpath --relative-to="$basedir" "$filename") + filename="${filename%.md}.html" + if [ "${filename##*/}" = "index.html" ]; then + filename=${filename%index.html} + fi + echo "$filename" } get_subpages_basedir() { - filename=$(basename "$1") - if [ "$filename" = "index.md" ]; then - dirname "$1" - else - echo "${1%.md}" + filename=$1 + if [ "${filename##*/}" = "index.md" ]; then + filename=$(dirname "$filename") fi + echo "$filename" } get_subpages() { @@ -39,10 +53,11 @@ get_subpages() { fi if [ ${#child_pages[@]} -ne 0 ]; then - echo -e "\033[0;90m[////////]\033[0m Child pages:" + echo -e "\033[0;90m[////////]\033[0m Child pages:" for file in "${child_pages[@]}"; do - echo -e "\033[0;90m[////////]\033[0m - $file" + link=$(target_url_rel "$basedir" "$file") + echo -e "\033[0;90m[////////]\033[0m - $file -> rel. URL: $link" done fi } @@ -77,14 +92,14 @@ handle () { } if [ -z "$1" ]; then - find content/ \ + find "$CONTENT_DIR" \ -type f \ | while read file do handle "$file" done elif [ "$1" = "all_md" ]; then - find content/ \ + find "$CONTENT_DIR" \ -type f \ -name "*.md" \ | while read file -- cgit v1.2.3-70-g09d2