summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build_content.sh171
-rwxr-xr-xscripts/metadata_tpl.json3
2 files changed, 113 insertions, 61 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh
index b258449..e2b3bb3 100755
--- a/scripts/build_content.sh
+++ b/scripts/build_content.sh
@@ -1,13 +1,13 @@
1#!/bin/bash 1#!/bin/bash
2 2
3SITE="https://volpeon.ink/"
4
3CONTENT_DIR="content/" 5CONTENT_DIR="content/"
4FILTERS_DIR="filters/" 6FILTERS_DIR="filters/"
5METADATA_DIR="metadata/" 7METADATA_DIR="metadata/"
6TEMPLATES_DIR="templates/" 8TEMPLATES_DIR="templates/"
7OUTPUT_DIR="output/" 9OUTPUT_DIR="output/"
8 10
9CATEGORY_MAP=$(cat "$METADATA_DIR/categories.json")
10
11get_filters() { 11get_filters() {
12 filters_args="" 12 filters_args=""
13 13
@@ -37,16 +37,22 @@ target_filename() {
37target_url_rel() { 37target_url_rel() {
38 basedir=$1 38 basedir=$1
39 filename=$2 39 filename=$2
40 ext=$3
40 filename=$(realpath --relative-to="$basedir" "$filename") 41 filename=$(realpath --relative-to="$basedir" "$filename")
41 filename="${filename%.md}.html" 42 filename="${filename%.md}.$ext"
42 if [ "${filename##*/}" = "index.html" ]; then 43 filename=${filename%index.html}
43 filename=${filename%index.html}
44 fi
45 echo "$filename" 44 echo "$filename"
46} 45}
47 46
48target_url_abs() { 47target_url_abs() {
49 echo "/$(target_url_rel "$CONTENT_DIR" "$1")" 48 echo "/$(target_url_rel "$CONTENT_DIR" "$1" "$2")"
49}
50
51metadata() {
52 pandoc "$1" \
53 -f markdown \
54 -t plain \
55 --template scripts/metadata_tpl.json
50} 56}
51 57
52get_section() { 58get_section() {
@@ -65,7 +71,7 @@ get_subpages_basedir() {
65 echo "$filename" 71 echo "$filename"
66} 72}
67 73
68get_metadata() { 74get_subpages_meta() {
69 basedir=$(get_subpages_basedir "$1") 75 basedir=$(get_subpages_basedir "$1")
70 child_pages=() 76 child_pages=()
71 77
@@ -86,42 +92,44 @@ get_metadata() {
86 child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}") 92 child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}")
87 fi 93 fi
88 94
95 pages=$(echo "{}" | jq ". + { \
96 all: [], \
97 by_year: {} \
98 }")
99
89 if [ ${#child_pages[@]} -ne 0 ]; then 100 if [ ${#child_pages[@]} -ne 0 ]; then
90 #echo -e "\033[0;90m[////////]\033[0m Child pages:" 101 #echo -e "\033[0;90m[////////]\033[0m Child pages:"
91 102
92 pages=$(echo "{}" | jq ". + { \
93 all: [], \
94 by_year: {} \
95 }")
96
97 categories="{}"
98
99 for file in "${child_pages[@]}"; do 103 for file in "${child_pages[@]}"; do
100 #echo -e "\033[0;90m[////////]\033[0m - $file" 104 #echo -e "\033[0;90m[////////]\033[0m - $file"
101 105
102 url_rel=$(target_url_rel "$basedir" "$file") 106 metadata=$(metadata "$file")
103 url_abs=$(target_url_abs "$file")
104 107
105 metadata=$(pandoc "$file" \ 108 url_rel=$(target_url_rel "$basedir" "$file" "html")
106 -f markdown \ 109 url_abs=$(target_url_abs "$file" "html")
107 -t plain \ 110 url_full="${SITE%/}$url_abs"
108 --template scripts/metadata_tpl.json)
109 111
110 date=$(echo "$metadata" | jq -r .date) 112 date=$(echo "$metadata" | jq -r .date)
111 category=$(echo "$metadata" | jq -r .category) 113 date_rfc3339=""
112 category_name=$(echo "$CATEGORY_MAP" | jq -r .$category)
113 114
114 metadata=$(echo "$metadata" | jq ". + { \ 115 if [ "$date" != "" ]; then
115 url_rel: \"$url_rel\", \ 116 date_rfc3339=$(date -d "$date" --rfc-3339=seconds | sed 's/ /T/')
116 url_abs: \"$url_abs\" \ 117 fi
118
119 metadata=$(echo "$metadata" | jq ". * { \
120 date: { \
121 yyyy_mm_dd: \"$date\", \
122 rfc3339: \"$date_rfc3339\" \
123 }, \
124 url: { \
125 rel: \"$url_rel\", \
126 abs: \"$url_abs\", \
127 full: \"$url_full\" \
128 } \
117 }") 129 }")
118 130
119 pages=$(echo "$pages" | jq ".all += [ $metadata ]") 131 pages=$(echo "$pages" | jq ".all += [ $metadata ]")
120 132
121 if [ "$category" != "" ]; then
122 categories=$(echo "$categories" | jq ". + { $category: \"$category_name\" }")
123 fi
124
125 if [ "$date" != "" ]; then 133 if [ "$date" != "" ]; then
126 date_year=$(date -d "$date" +%Y) 134 date_year=$(date -d "$date" +%Y)
127 #date_month=$(date -d "$date" +%m) 135 #date_month=$(date -d "$date" +%m)
@@ -135,58 +143,101 @@ get_metadata() {
135 | jq ".all |= (sort_by(.date) | reverse) \ 143 | jq ".all |= (sort_by(.date) | reverse) \
136 | .by_year |= (to_entries | sort_by(.key) | reverse \ 144 | .by_year |= (to_entries | sort_by(.key) | reverse \
137 | .[].value |= (sort_by(.date) | reverse))") 145 | .[].value |= (sort_by(.date) | reverse))")
138
139 categories=$(echo "$categories" | jq ". | to_entries | sort_by(.key)")
140
141 echo "{}" | jq ". + { \
142 pages: $pages, \
143 categories: $categories \
144 }"
145 fi 146 fi
147
148 echo "{}" | jq ". + { \
149 pages: $pages \
150 }"
146} 151}
147 152
148handle () { 153handle () {
149 target=$(target_filename "$1") 154 target_file=$(target_filename "$1")
150 155
151 mkdir -p $(dirname "$target") 156 mkdir -p $(dirname "$target_file")
152 157
153 if [ "${1#*.}" = "md" ]; then 158 if [ "${1#*.}" = "md" ]; then
154 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target" 159 echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target_file"
160
161 meta_file=$(mktemp)
162
163 metadata=$(metadata "$file")
164 metadata=$(echo "[ \
165 $metadata, \
166 $(get_subpages_meta "$1") \
167 ]" | jq ".[0] * .[1]")
168
169 url_abs=$(target_url_abs "$1" "html")
170 url_full="${SITE%/}$url_abs"
155 171
156 is_home=false
157 section=$(get_section "$1") 172 section=$(get_section "$1")
158 173
159 if [ "$target" = "${OUTPUT_DIR}index.html" ]; then 174 is_home=false
175 if [ "$target_file" = "${OUTPUT_DIR}index.html" ]; then
160 is_home=true 176 is_home=true
161 fi 177 fi
162 178
163 subpages_meta_file=$(mktemp) 179 metadata=$(echo "$metadata" | jq ". * { \
180 url: { \
181 abs: \"$url_abs\", \
182 full: \"$url_full\" \
183 }, \
184 section: { \
185 id: \"$section\", \
186 is_$section: true \
187 }, \
188 is_home: $is_home \
189 }")
164 190
165 # echo "$(get_metadata "$1")" 191 create_feed=$(echo "$metadata" | jq -r ".create_feed")
166 echo "$(get_metadata "$1")" > "$subpages_meta_file" 192
193 if [ "$create_feed" = "true" ]; then
194 feed_target_file="${target_file%.html}.xml"
195 feed_url_abs="$(target_url_abs "$1" "xml")"
196 feed_url_full="${SITE%/}$feed_url_abs"
197 last_update=$(echo "$metadata" | jq -r ".pages.all[0].date")
198
199 metadata=$(echo "$metadata" | jq ". * { \
200 feed: { \
201 last_update: $last_update, \
202 url: { \
203 abs: \"$feed_url_abs\", \
204 full: \"$feed_url_full\" \
205 } \
206 } \
207 }")
167 208
168 # echo $(pandoc "$1" \ 209 echo "$metadata" > "$meta_file"
169 # -f markdown \ 210
170 # -t json) 211 pandoc "$1" \
212 -f markdown \
213 -t html5 \
214 --template "${TEMPLATES_DIR}feed.xml" \
215 -o "$feed_target_file" \
216 --metadata-file metadata/metadata.yaml \
217 --metadata-file "$meta_file" \
218 $FILTERS
219 fi
220
221 echo "$metadata" > "$meta_file"
171 222
172 pandoc "$1" \ 223 pandoc "$1" \
173 -f markdown \ 224 -f markdown \
174 -t html5 \ 225 -t html5 \
175 --template "${TEMPLATES_DIR}base.html" \ 226 --template "${TEMPLATES_DIR}base.html" \
176 -o "$target" \ 227 -o "$target_file" \
177 --metadata "ishome"=$is_home \
178 --metadata section=$section \
179 --metadata "is$section" \
180 --metadata-file metadata/metadata.yaml \ 228 --metadata-file metadata/metadata.yaml \
181 --metadata-file "$subpages_meta_file" \ 229 --metadata-file "$meta_file" \
182 $FILTERS 230 $FILTERS
183 # --lua-filter "filters/add_refs.lua"
184 231
185 rm "$subpages_meta_file" 232 rm "$meta_file"
233
234 # echo $(pandoc "$1" \
235 # -f markdown \
236 # -t json)
186 else 237 else
187 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target" 238 echo -e "\033[0;32m[COPY ]\033[0m $1 -> $target_file"
188 239
189 cp "$1" "$target" 240 cp "$1" "$target_file"
190 fi 241 fi
191} 242}
192 243
@@ -215,9 +266,9 @@ elif [ "$1" = "delete" ]; then
215 if [ -z "$2" ]; then 266 if [ -z "$2" ]; then
216 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" 267 echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument"
217 else 268 else
218 TARGET=$(target_filename "$2") 269 target_file=$(target_filename "$2")
219 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $TARGET" 270 echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file"
220 rm -rf $TARGET 271 rm -rf $target_file
221 fi 272 fi
222else 273else
223 echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\"" 274 echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\""
diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json
index 76e4439..79eabe1 100755
--- a/scripts/metadata_tpl.json
+++ b/scripts/metadata_tpl.json
@@ -1,5 +1,6 @@
1{ 1{
2 "title": "$title$", 2 "title": "$title$",
3 "date": "$date$", 3 "date": "$date$",
4 "category": "$category$" 4 "category": "$category$",
5 "create_feed": "$create_feed$"
5} 6}