summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build_content.sh74
-rwxr-xr-xscripts/watch_content.sh10
-rwxr-xr-xscripts/watch_metadata.sh2
-rwxr-xr-xscripts/watch_sass.sh2
-rwxr-xr-xscripts/watch_templates.sh2
5 files changed, 69 insertions, 21 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
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 @@
1#!/bin/bash 1#!/bin/bash
2 2
3inotifywait -qrme close_write,delete,move --format "%w%f" content \ 3inotifywait -qrme close_write,delete,move --format "%w%f" content \
4 | while read FILENAME 4 | while read file
5 do 5 do
6 if [ -f "$FILENAME" ]; then 6 if [ -f "$file" ]; then
7 scripts/build_content.sh "single" "$FILENAME" 7 scripts/build_content.sh "single" "$file"
8 elif [ ! -d "$FILENAME" ]; then 8 elif [ ! -d "$file" ]; then
9 scripts/build_content.sh "delete" "$FILENAME" 9 scripts/build_content.sh "delete" "$file"
10 fi 10 fi
11 done 11 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 @@
1#!/bin/bash 1#!/bin/bash
2 2
3inotifywait -qrme close_write,delete,move --format "%w%f" metadata \ 3inotifywait -qrme close_write,delete,move --format "%w%f" metadata \
4 | while read FILENAME 4 | while read file
5 do 5 do
6 scripts/build_content.sh "all_md" 6 scripts/build_content.sh "all_md"
7 done 7 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 @@
1#!/bin/bash 1#!/bin/bash
2 2
3inotifywait -qrme close_write,delete,move --format "%w%f" assets \ 3inotifywait -qrme close_write,delete,move --format "%w%f" assets \
4 | while read FILENAME 4 | while read file
5 do 5 do
6 scripts/build_sass.sh 6 scripts/build_sass.sh
7 done 7 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 @@
1#!/bin/bash 1#!/bin/bash
2 2
3inotifywait -qrme close_write,delete,move --format "%w%f" templates \ 3inotifywait -qrme close_write,delete,move --format "%w%f" templates \
4 | while read FILENAME 4 | while read file
5 do 5 do
6 scripts/build_content.sh "all_md" 6 scripts/build_content.sh "all_md"
7 done 7 done