summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build_content.sh33
-rw-r--r--scripts/metadata_filter.lua17
2 files changed, 31 insertions, 19 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh
index 8bcf7c2..c20eca8 100755
--- a/scripts/build_content.sh
+++ b/scripts/build_content.sh
@@ -32,6 +32,7 @@ get_metadata() {
32 --metadata content_dir="$CONTENT_DIR" \ 32 --metadata content_dir="$CONTENT_DIR" \
33 --metadata output_dir="$OUTPUT_DIR" \ 33 --metadata output_dir="$OUTPUT_DIR" \
34 --metadata file_in="$1" \ 34 --metadata file_in="$1" \
35 --metadata relative_to="$2" \
35 --metadata-file metadata/metadata.yaml \ 36 --metadata-file metadata/metadata.yaml \
36 --no-highlight \ 37 --no-highlight \
37 --template scripts/metadata_tpl.json \ 38 --template scripts/metadata_tpl.json \
@@ -50,37 +51,32 @@ get_content() {
50 --lua-filter scripts/metadata_filter.lua 51 --lua-filter scripts/metadata_filter.lua
51} 52}
52 53
53get_subpages_basedir() {
54 local filename=$1
55 filename=${filename%.md}
56 if [ "${filename##*/}" = "index" ]; then
57 filename=${filename%/index}
58 fi
59 echo "$filename"
60}
61
62get_subpages_metadata() { 54get_subpages_metadata() {
63 local base_dir_in=$(get_subpages_basedir "$1") 55 local base_dir_in=${1%/index.md}
56 local relative_to="$2"
57 if [ -z "$2" ]; then
58 relative_to="$1"
59 fi
64 local child_pages=() 60 local child_pages=()
65 61
66 if [ -d "$base_dir_in" ]; then 62 if [ -d "$base_dir_in" ]; then
67 mapfile -d $'\0' child_pages < <(find "$base_dir_in" \ 63 mapfile -d $'\0' child_pages < <(find "$base_dir_in" \
68 -maxdepth 2 \ 64 -maxdepth 2 \
69 -type f \ 65 -type f \
70 -name "*.md" \ 66 -wholename "$base_dir_in/*/index.md" \
71 ! -name "_*.md" \ 67 ! -name "_*.md" \
72 ! -wholename "$base_dir_in/index.md" \
73 \( -wholename "$base_dir_in/*/index.md" -o ! -wholename "$base_dir_in/*/*.md" \) \
74 -print0) 68 -print0)
75 fi 69 fi
76 70
77 local pages="[]" 71 local pages="[]"
72 local sections="{}"
78 73
79 for file_in in "${child_pages[@]}"; do 74 for file_in in "${child_pages[@]}"; do
75 local section=$(basename "${file_in%/index.md}")
80 local content=$(get_content "$file_in" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g') 76 local content=$(get_content "$file_in" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g')
81
82 local metadata=$(get_metadata "$file_in" | jq "{ \ 77 local metadata=$(get_metadata "$file_in" | jq "{ \
83 file_out: .file_out, \ 78 file_out: .file_out, \
79 url: .url, \
84 author: .author, \ 80 author: .author, \
85 title: .title, \ 81 title: .title, \
86 date: .date, \ 82 date: .date, \
@@ -88,11 +84,18 @@ get_subpages_metadata() {
88 category: .category, \ 84 category: .category, \
89 content: \"$content\" \ 85 content: \"$content\" \
90 } | del(.[] | nulls)") 86 } | del(.[] | nulls)")
87 local title=$(echo "$metadata" | jq ".title")
88 local subpages="[]"
89
90 if [ -z "$2" ]; then
91 subpages=$(get_subpages_metadata "$file_in" "$1" | jq ".pages")
92 fi
91 93
92 pages=$(echo "$pages" | jq ". += [ $metadata ]") 94 pages=$(echo "$pages" | jq ". += [ $metadata ]")
95 sections=$(echo "$sections" | jq ". += { \"$section\": { title: $title, pages: $subpages } }")
93 done 96 done
94 97
95 echo "{ \"pages\": $pages }" 98 echo "{ \"pages\": $pages, \"sections\": $sections }"
96} 99}
97 100
98handle () { 101handle () {
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua
index 7823130..499cf3e 100644
--- a/scripts/metadata_filter.lua
+++ b/scripts/metadata_filter.lua
@@ -260,8 +260,14 @@ function Meta(meta)
260 260
261 meta.file_out = get_file_out(meta.rewrites, meta.content_dir, 261 meta.file_out = get_file_out(meta.rewrites, meta.content_dir,
262 meta.output_dir, meta.file_in) 262 meta.output_dir, meta.file_in)
263 if meta.relative_to == nil then
264 meta.relative_to = meta.file_in
265 end
266 meta.relative_to_out = get_file_out(meta.rewrites, meta.content_dir,
267 meta.output_dir, meta.relative_to)
263 268
264 meta.url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, meta.file_out) 269 meta.url = resolve_url(meta.site.url, meta.output_dir, meta.relative_to_out,
270 meta.file_out)
265 271
266 meta.date = format_date(meta.date) 272 meta.date = format_date(meta.date)
267 if meta.last_update ~= nil then 273 if meta.last_update ~= nil then
@@ -276,14 +282,16 @@ function Meta(meta)
276 282
277 if meta.page_type == "feed" then 283 if meta.page_type == "feed" then
278 meta.page = pandoc.MetaMap({ 284 meta.page = pandoc.MetaMap({
279 url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, 285 url = resolve_url(meta.site.url, meta.output_dir,
286 meta.relative_to_out,
280 meta.file_out:gsub("%.xml$", ".html")) 287 meta.file_out:gsub("%.xml$", ".html"))
281 }) 288 })
282 end 289 end
283 290
284 if meta.create_feed then 291 if meta.create_feed then
285 meta.feed = pandoc.MetaMap({ 292 meta.feed = pandoc.MetaMap({
286 url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, 293 url = resolve_url(meta.site.url, meta.output_dir,
294 meta.relative_to_out,
287 meta.file_out:gsub("%.html$", ".xml")) 295 meta.file_out:gsub("%.html$", ".xml"))
288 }) 296 })
289 end 297 end
@@ -296,7 +304,8 @@ function Meta(meta)
296 if meta.pages then 304 if meta.pages then
297 local pages, categories = organize_subpages(meta.site.url, 305 local pages, categories = organize_subpages(meta.site.url,
298 meta.output_dir, 306 meta.output_dir,
299 meta.file_out, meta.pages) 307 meta.relative_to_out,
308 meta.pages)
300 meta.pages = pages 309 meta.pages = pages
301 meta.categories = categories 310 meta.categories = categories
302 end 311 end