summaryrefslogtreecommitdiffstats
path: root/scripts/build_content.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build_content.sh')
-rwxr-xr-xscripts/build_content.sh73
1 files changed, 26 insertions, 47 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh
index 63bc525..97f57a3 100755
--- a/scripts/build_content.sh
+++ b/scripts/build_content.sh
@@ -26,29 +26,16 @@ FILTERS=$(get_filters)
26get_filename_out() { 26get_filename_out() {
27 local filename=$1 27 local filename=$1
28 filename=${filename#"$CONTENT_DIR"} 28 filename=${filename#"$CONTENT_DIR"}
29 if [ "${filename##*.}" = "md" ]; then
30 filename="${filename%.md}.html"
31 fi
32 if [ "${filename##*/}" != "index.html" ]; then
33 filename="${filename%.html}/index.html"
34 fi
35 echo "$OUTPUT_DIR$filename" 29 echo "$OUTPUT_DIR$filename"
36} 30}
37 31
38get_metadata() { 32get_metadata() {
39 local file_out=$(get_filename_out "$1")
40 local base_file_out="$2"
41
42 if [ -z "$2" ]; then
43 base_file_out="$file_out"
44 fi
45
46 pandoc "$1" \ 33 pandoc "$1" \
47 -f markdown \ 34 -f markdown \
48 -t plain \ 35 -t plain \
36 --metadata content_dir="$CONTENT_DIR" \
49 --metadata output_dir="$OUTPUT_DIR" \ 37 --metadata output_dir="$OUTPUT_DIR" \
50 --metadata base_file_out="$base_file_out" \ 38 --metadata file_in="$1" \
51 --metadata file_out="$file_out" \
52 --metadata-file metadata/metadata.yaml \ 39 --metadata-file metadata/metadata.yaml \
53 --no-highlight \ 40 --no-highlight \
54 --template scripts/metadata_tpl.json \ 41 --template scripts/metadata_tpl.json \
@@ -56,19 +43,12 @@ get_metadata() {
56} 43}
57 44
58get_content() { 45get_content() {
59 local file_out=$(get_filename_out "$1")
60 local base_file_out="$2"
61
62 if [ -z "$2" ]; then
63 base_file_out="$file_out"
64 fi
65
66 pandoc "$1" \ 46 pandoc "$1" \
67 -f markdown \ 47 -f markdown \
68 -t markdown \ 48 -t markdown \
49 --metadata content_dir="$CONTENT_DIR" \
69 --metadata output_dir="$OUTPUT_DIR" \ 50 --metadata output_dir="$OUTPUT_DIR" \
70 --metadata base_file_out="$base_file_out" \ 51 --metadata file_in="$1" \
71 --metadata file_out="$file_out" \
72 --metadata-file metadata/metadata.yaml \ 52 --metadata-file metadata/metadata.yaml \
73 --no-highlight \ 53 --no-highlight \
74 --lua-filter scripts/metadata_filter.lua 54 --lua-filter scripts/metadata_filter.lua
@@ -84,9 +64,7 @@ get_subpages_basedir() {
84} 64}
85 65
86get_subpages_metadata() { 66get_subpages_metadata() {
87 local base_file_in=$1 67 local base_dir_in=$(get_subpages_basedir "$1")
88 local base_file_out=$2
89 local base_dir_in=$(get_subpages_basedir "$base_file_in")
90 local child_pages=() 68 local child_pages=()
91 69
92 if [ -d "$base_dir_in" ]; then 70 if [ -d "$base_dir_in" ]; then
@@ -103,10 +81,10 @@ get_subpages_metadata() {
103 local pages="[]" 81 local pages="[]"
104 82
105 for file_in in "${child_pages[@]}"; do 83 for file_in in "${child_pages[@]}"; do
106 local content=$(get_content "$file_in" "$base_file_out" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\"/g') 84 local content=$(get_content "$file_in" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\"/g')
107 85
108 local metadata=$(get_metadata "$file_in" "$base_file_out" | jq "{ \ 86 local metadata=$(get_metadata "$file_in" | jq "{ \
109 url: .url, \ 87 file_out: .file_out, \
110 author: .author, \ 88 author: .author, \
111 title: .title, \ 89 title: .title, \
112 date: .date, \ 90 date: .date, \
@@ -122,19 +100,18 @@ get_subpages_metadata() {
122} 100}
123 101
124handle () { 102handle () {
125 local file_out=$(get_filename_out "$1") 103 if [ "${1#*.}" = "md" ]; then
104 local included_metadata=$(get_metadata "$1")
105 local file_out=$(echo "$included_metadata" | jq -r .file_out)
106 local create_feed=$(echo "$included_metadata" | jq -r .create_feed)
126 107
127 mkdir -p $(dirname "$file_out") 108 mkdir -p $(dirname "$file_out")
128 109
129 if [ "${1#*.}" = "md" ]; then
130 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $file_out" 110 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $file_out"
131 111
132 echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata" 112 echo -e "\033[0;90m[COMPILE ]\033[0m Getting subpages"
133
134 local included_metadata=$(get_metadata "$1")
135 local added_metadata=$(get_subpages_metadata "$1" "$file_out")
136 113
137 local create_feed=$(echo "$included_metadata" | jq -r .create_feed) 114 local added_metadata=$(get_subpages_metadata "$1")
138 115
139 local meta_file=$(mktemp) 116 local meta_file=$(mktemp)
140 117
@@ -143,16 +120,15 @@ handle () {
143 if [ "$create_feed" = "true" ]; then 120 if [ "$create_feed" = "true" ]; then
144 echo -e "\033[0;90m[COMPILE ]\033[0m Creating feed" 121 echo -e "\033[0;90m[COMPILE ]\033[0m Creating feed"
145 122
146 local feed_file_out="${file_out%.html}.xml"
147
148 pandoc "$1" \ 123 pandoc "$1" \
149 -f markdown \ 124 -f markdown \
150 -t html5 \ 125 -t html5 \
151 --no-highlight \ 126 --no-highlight \
152 --template "${TEMPLATES_DIR}feed.xml" \ 127 --template "${TEMPLATES_DIR}feed.xml" \
153 -o "$feed_file_out" \ 128 -o "${file_out%.html}.xml" \
129 --metadata content_dir="$CONTENT_DIR" \
154 --metadata output_dir="$OUTPUT_DIR" \ 130 --metadata output_dir="$OUTPUT_DIR" \
155 --metadata file_out="$feed_file_out" \ 131 --metadata file_in="$1" \
156 --metadata page_type=feed \ 132 --metadata page_type=feed \
157 --metadata-file metadata/metadata.yaml \ 133 --metadata-file metadata/metadata.yaml \
158 --metadata-file "$meta_file" \ 134 --metadata-file "$meta_file" \
@@ -167,8 +143,9 @@ handle () {
167 --no-highlight \ 143 --no-highlight \
168 --template "${TEMPLATES_DIR}base.html" \ 144 --template "${TEMPLATES_DIR}base.html" \
169 -o "$file_out" \ 145 -o "$file_out" \
146 --metadata content_dir="$CONTENT_DIR" \
170 --metadata output_dir="$OUTPUT_DIR" \ 147 --metadata output_dir="$OUTPUT_DIR" \
171 --metadata file_out="$file_out" \ 148 --metadata file_in="$1" \
172 --metadata-file metadata/metadata.yaml \ 149 --metadata-file metadata/metadata.yaml \
173 --metadata-file "$meta_file" \ 150 --metadata-file "$meta_file" \
174 --lua-filter scripts/metadata_filter.lua \ 151 --lua-filter scripts/metadata_filter.lua \
@@ -179,8 +156,9 @@ handle () {
179 # -t plain \ 156 # -t plain \
180 # --no-highlight \ 157 # --no-highlight \
181 # --template scripts/metadata_tpl.json \ 158 # --template scripts/metadata_tpl.json \
159 # --metadata content_dir="$CONTENT_DIR" \
182 # --metadata output_dir="$OUTPUT_DIR" \ 160 # --metadata output_dir="$OUTPUT_DIR" \
183 # --metadata file_out="$file_out" \ 161 # --metadata file_in="$1" \
184 # --metadata-file metadata/metadata.yaml \ 162 # --metadata-file metadata/metadata.yaml \
185 # --metadata-file "$meta_file" \ 163 # --metadata-file "$meta_file" \
186 # --lua-filter scripts/metadata_filter.lua \ 164 # --lua-filter scripts/metadata_filter.lua \
@@ -188,11 +166,12 @@ handle () {
188 166
189 rm "$meta_file" 167 rm "$meta_file"
190 168
191 # echo "$included_metadata"
192 # echo "$added_metadata"
193
194 echo -e "\033[0;90m[COMPILE ]\033[0m Done" 169 echo -e "\033[0;90m[COMPILE ]\033[0m Done"
195 else 170 else
171 local file_out=$(get_filename_out "$1")
172
173 mkdir -p $(dirname "$file_out")
174
196 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $file_out" 175 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $file_out"
197 176
198 cp "$1" "$file_out" 177 cp "$1" "$file_out"