summaryrefslogtreecommitdiffstats
path: root/scripts/build_content.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build_content.sh')
-rwxr-xr-xscripts/build_content.sh74
1 files changed, 61 insertions, 13 deletions
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 @@
1#!/bin/bash 1#!/bin/bash
2 2
3target () { 3target_filename () {
4 if [ "${1#*.}" = "md" ]; then 4 if [ "${1#*.}" = "md" ]; then
5 echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)" 5 echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)"
6 else 6 else
@@ -8,40 +8,88 @@ target () {
8 fi 8 fi
9} 9}
10 10
11get_subpages_basedir() {
12 filename=$(basename "$1")
13 if [ "$filename" = "index.md" ]; then
14 dirname "$1"
15 else
16 echo "${1%.md}"
17 fi
18}
19
20get_subpages() {
21 basedir=$(get_subpages_basedir "$1")
22 child_pages=()
23
24 if [ -d "$basedir" ]; then
25 mapfile -d $'\0' child_pages_1 < <(find $basedir/ \
26 -type f \
27 -name "*.md" ! -name "index.md" \
28 -maxdepth 1 \
29 -print0)
30
31 mapfile -d $'\0' child_pages_2 < <(find $basedir/ \
32 -type f \
33 -name "index.md" \
34 -mindepth 2 \
35 -maxdepth 2 \
36 -print0)
37
38 child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}")
39 fi
40
41 if [ ${#child_pages[@]} -ne 0 ]; then
42 echo -e "\033[0;90m[////////]\033[0m Child pages:"
43
44 for file in "${child_pages[@]}"; do
45 echo -e "\033[0;90m[////////]\033[0m - $file"
46 done
47 fi
48}
49
11handle () { 50handle () {
12 TARGET=$(target "$1") 51 target=$(target_filename "$1")
13 mkdir -p $(dirname "$TARGET") 52 mkdir -p $(dirname "$target")
14 53
15 if [ "${1#*.}" = "md" ]; then 54 if [ "${1#*.}" = "md" ]; then
16 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $TARGET" 55 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target"
56
57 subpages_meta=$(mktemp)
58
59 # $(get_subpages "$1") > "$subpages_meta"
60
61 get_subpages "$1"
17 62
18 pandoc "$1" \ 63 pandoc "$1" \
19 -f markdown \ 64 -f markdown \
20 -t html5 \ 65 -t html5 \
21 --template templates/base.html \ 66 --template templates/base.html \
22 -o "$TARGET" \ 67 -o "$target" \
23 --metadata-file metadata/metadata.json 68 --metadata-file metadata/metadata.yaml \
69 --metadata-file "$subpages_meta"
70
71 rm "$subpages_meta"
24 else 72 else
25 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $TARGET" 73 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target"
26 74
27 cp "$1" "$TARGET" 75 cp "$1" "$target"
28 fi 76 fi
29} 77}
30 78
31if [ -z "$1" ]; then 79if [ -z "$1" ]; then
32 find content/ \ 80 find content/ \
33 -type f \ 81 -type f \
34 | while read FILE 82 | while read file
35 do 83 do
36 handle "$FILE" 84 handle "$file"
37 done 85 done
38elif [ "$1" = "all_md" ]; then 86elif [ "$1" = "all_md" ]; then
39 find content/ \ 87 find content/ \
40 -type f \ 88 -type f \
41 -name "*.md" \ 89 -name "*.md" \
42 | while read FILE 90 | while read file
43 do 91 do
44 handle "$FILE" 92 handle "$file"
45 done 93 done
46elif [ "$1" = "single" ]; then 94elif [ "$1" = "single" ]; then
47 if [ -z "$2" ]; then 95 if [ -z "$2" ]; then
@@ -53,7 +101,7 @@ elif [ "$1" = "delete" ]; then
53 if [ -z "$2" ]; then 101 if [ -z "$2" ]; then
54 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" 102 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument"
55 else 103 else
56 TARGET=$(target "$2") 104 TARGET=$(target_filename "$2")
57 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $TARGET" 105 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $TARGET"
58 rm -rf $TARGET 106 rm -rf $TARGET
59 fi 107 fi