diff options
-rwxr-xr-x | scripts/build_content.sh | 41 |
1 files 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 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CONTENT_DIR="content/" | ||
4 | OUTPUT_DIR="output/" | ||
5 | |||
3 | target_filename () { | 6 | target_filename () { |
4 | if [ "${1#*.}" = "md" ]; then | 7 | filename=$1 |
5 | echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)" | 8 | filename=${filename#"$CONTENT_DIR"} |
6 | else | 9 | if [ "${filename##*.}" = "md" ]; then |
7 | echo "output/$(echo "$1" | cut -sd / -f 2-)" | 10 | filename="${filename%.md}.html" |
8 | fi | 11 | fi |
12 | echo "$OUTPUT_DIR$filename" | ||
13 | } | ||
14 | |||
15 | target_url_rel () { | ||
16 | basedir=$1 | ||
17 | filename=$2 | ||
18 | filename=$(realpath --relative-to="$basedir" "$filename") | ||
19 | filename="${filename%.md}.html" | ||
20 | if [ "${filename##*/}" = "index.html" ]; then | ||
21 | filename=${filename%index.html} | ||
22 | fi | ||
23 | echo "$filename" | ||
9 | } | 24 | } |
10 | 25 | ||
11 | get_subpages_basedir() { | 26 | get_subpages_basedir() { |
12 | filename=$(basename "$1") | 27 | filename=$1 |
13 | if [ "$filename" = "index.md" ]; then | 28 | if [ "${filename##*/}" = "index.md" ]; then |
14 | dirname "$1" | 29 | filename=$(dirname "$filename") |
15 | else | ||
16 | echo "${1%.md}" | ||
17 | fi | 30 | fi |
31 | echo "$filename" | ||
18 | } | 32 | } |
19 | 33 | ||
20 | get_subpages() { | 34 | get_subpages() { |
@@ -39,10 +53,11 @@ get_subpages() { | |||
39 | fi | 53 | fi |
40 | 54 | ||
41 | if [ ${#child_pages[@]} -ne 0 ]; then | 55 | if [ ${#child_pages[@]} -ne 0 ]; then |
42 | echo -e "\033[0;90m[////////]\033[0m Child pages:" | 56 | echo -e "\033[0;90m[////////]\033[0m Child pages:" |
43 | 57 | ||
44 | for file in "${child_pages[@]}"; do | 58 | for file in "${child_pages[@]}"; do |
45 | echo -e "\033[0;90m[////////]\033[0m - $file" | 59 | link=$(target_url_rel "$basedir" "$file") |
60 | echo -e "\033[0;90m[////////]\033[0m - $file -> rel. URL: $link" | ||
46 | done | 61 | done |
47 | fi | 62 | fi |
48 | } | 63 | } |
@@ -77,14 +92,14 @@ handle () { | |||
77 | } | 92 | } |
78 | 93 | ||
79 | if [ -z "$1" ]; then | 94 | if [ -z "$1" ]; then |
80 | find content/ \ | 95 | find "$CONTENT_DIR" \ |
81 | -type f \ | 96 | -type f \ |
82 | | while read file | 97 | | while read file |
83 | do | 98 | do |
84 | handle "$file" | 99 | handle "$file" |
85 | done | 100 | done |
86 | elif [ "$1" = "all_md" ]; then | 101 | elif [ "$1" = "all_md" ]; then |
87 | find content/ \ | 102 | find "$CONTENT_DIR" \ |
88 | -type f \ | 103 | -type f \ |
89 | -name "*.md" \ | 104 | -name "*.md" \ |
90 | | while read file | 105 | | while read file |