From 9e373cfbb0bd98480560a00978fd6d51113ffe06 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Thu, 15 Apr 2021 20:21:14 +0200 Subject: Fetch pages of sections --- scripts/build_content.sh | 33 ++++++++++++++++++--------------- scripts/metadata_filter.lua | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'scripts') 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() { --metadata content_dir="$CONTENT_DIR" \ --metadata output_dir="$OUTPUT_DIR" \ --metadata file_in="$1" \ + --metadata relative_to="$2" \ --metadata-file metadata/metadata.yaml \ --no-highlight \ --template scripts/metadata_tpl.json \ @@ -50,37 +51,32 @@ get_content() { --lua-filter scripts/metadata_filter.lua } -get_subpages_basedir() { - local filename=$1 - filename=${filename%.md} - if [ "${filename##*/}" = "index" ]; then - filename=${filename%/index} - fi - echo "$filename" -} - get_subpages_metadata() { - local base_dir_in=$(get_subpages_basedir "$1") + local base_dir_in=${1%/index.md} + local relative_to="$2" + if [ -z "$2" ]; then + relative_to="$1" + fi local child_pages=() if [ -d "$base_dir_in" ]; then mapfile -d $'\0' child_pages < <(find "$base_dir_in" \ -maxdepth 2 \ -type f \ - -name "*.md" \ + -wholename "$base_dir_in/*/index.md" \ ! -name "_*.md" \ - ! -wholename "$base_dir_in/index.md" \ - \( -wholename "$base_dir_in/*/index.md" -o ! -wholename "$base_dir_in/*/*.md" \) \ -print0) fi local pages="[]" + local sections="{}" for file_in in "${child_pages[@]}"; do + local section=$(basename "${file_in%/index.md}") local content=$(get_content "$file_in" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g') - local metadata=$(get_metadata "$file_in" | jq "{ \ file_out: .file_out, \ + url: .url, \ author: .author, \ title: .title, \ date: .date, \ @@ -88,11 +84,18 @@ get_subpages_metadata() { category: .category, \ content: \"$content\" \ } | del(.[] | nulls)") + local title=$(echo "$metadata" | jq ".title") + local subpages="[]" + + if [ -z "$2" ]; then + subpages=$(get_subpages_metadata "$file_in" "$1" | jq ".pages") + fi pages=$(echo "$pages" | jq ". += [ $metadata ]") + sections=$(echo "$sections" | jq ". += { \"$section\": { title: $title, pages: $subpages } }") done - echo "{ \"pages\": $pages }" + echo "{ \"pages\": $pages, \"sections\": $sections }" } handle () { 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) meta.file_out = get_file_out(meta.rewrites, meta.content_dir, meta.output_dir, meta.file_in) + if meta.relative_to == nil then + meta.relative_to = meta.file_in + end + meta.relative_to_out = get_file_out(meta.rewrites, meta.content_dir, + meta.output_dir, meta.relative_to) - meta.url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, meta.file_out) + meta.url = resolve_url(meta.site.url, meta.output_dir, meta.relative_to_out, + meta.file_out) meta.date = format_date(meta.date) if meta.last_update ~= nil then @@ -276,14 +282,16 @@ function Meta(meta) if meta.page_type == "feed" then meta.page = pandoc.MetaMap({ - url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, + url = resolve_url(meta.site.url, meta.output_dir, + meta.relative_to_out, meta.file_out:gsub("%.xml$", ".html")) }) end if meta.create_feed then meta.feed = pandoc.MetaMap({ - url = resolve_url(meta.site.url, meta.output_dir, meta.file_out, + url = resolve_url(meta.site.url, meta.output_dir, + meta.relative_to_out, meta.file_out:gsub("%.html$", ".xml")) }) end @@ -296,7 +304,8 @@ function Meta(meta) if meta.pages then local pages, categories = organize_subpages(meta.site.url, meta.output_dir, - meta.file_out, meta.pages) + meta.relative_to_out, + meta.pages) meta.pages = pages meta.categories = categories end -- cgit v1.2.3-70-g09d2