From 2b58f2589efb48f7df112a2e175ce28b52f2f8f7 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 21 Apr 2021 17:12:50 +0200 Subject: Small build script and design improvements --- scripts/build_content.sh | 6 +----- scripts/metadata_filter.lua | 48 ++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 154a93f..3e4d512 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -30,7 +30,6 @@ get_metadata() { -f markdown \ -t plain \ --metadata content_dir="$CONTENT_DIR" \ - --metadata output_dir="$OUTPUT_DIR" \ --metadata file_in="$1" \ --metadata relative_to="$2" \ --metadata-file metadata/metadata.yaml \ @@ -44,7 +43,6 @@ get_content() { -f markdown \ -t markdown \ --metadata content_dir="$CONTENT_DIR" \ - --metadata output_dir="$OUTPUT_DIR" \ --metadata file_in="$1" \ --metadata-file metadata/metadata.yaml \ --no-highlight \ @@ -103,6 +101,7 @@ handle () { if [ "${1#*.}" = "md" ]; then local included_metadata=$(get_metadata "$1") local file_out=$(echo "$included_metadata" | jq -r .file_out) + file_out="$OUTPUT_DIR${file_out#/}" local create_feed=$(echo "$included_metadata" | jq -r .create_feed) mkdir -p $(dirname "$file_out") @@ -127,7 +126,6 @@ handle () { --template "${TEMPLATES_DIR}feed.xml" \ -o "${file_out%.html}.xml" \ --metadata content_dir="$CONTENT_DIR" \ - --metadata output_dir="$OUTPUT_DIR" \ --metadata file_in="$1" \ --metadata page_type=feed \ --metadata-file metadata/metadata.yaml \ @@ -144,7 +142,6 @@ handle () { --template "${TEMPLATES_DIR}base.html" \ -o "$file_out" \ --metadata content_dir="$CONTENT_DIR" \ - --metadata output_dir="$OUTPUT_DIR" \ --metadata file_in="$1" \ --metadata-file metadata/metadata.yaml \ --metadata-file "$meta_file" \ @@ -157,7 +154,6 @@ handle () { # --no-highlight \ # --template scripts/metadata_tpl.json \ # --metadata content_dir="$CONTENT_DIR" \ - # --metadata output_dir="$OUTPUT_DIR" \ # --metadata file_in="$1" \ # --metadata-file metadata/metadata.yaml \ # --metadata-file "$meta_file" \ diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 21698bd..ad2bb83 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -101,7 +101,7 @@ function apply_path_rewrites(rewrites, str) return str end -function get_file_out(rewrites, content_dir, output_dir, file_in) +function get_file_out(rewrites, content_dir, file_in) local file_out = file_in:gsub("^" .. content_dir, ""):gsub("%.md$", ".html") if file_out:match(".html$") and not file_out:match("/index%.html$") then @@ -110,15 +110,21 @@ function get_file_out(rewrites, content_dir, output_dir, file_in) file_out = apply_path_rewrites(rewrites, file_out) - return pandoc.MetaString(output_dir .. file_out) + return pandoc.MetaString(file_out) end -function resolve_url(site_url, output_dir, ref_file, target_file) +function make_absolute(rel, base) + return + rel:find("^/") ~= nil and rel or base:gsub("^(.*)/.-$", "%1") .. "/" .. + rel +end + +function resolve_url(site_url, ref_file, target_file) + target_file = target_file:gsub("/index%.html$", "/") + local ref_base_dir = ref_file:gsub("^(.*)/.-$", "%1") - local abs = target_file:gsub("^" .. output_dir, ""):gsub("/index%.html$", - "/") - local rel = - relative_to(ref_base_dir, target_file):gsub("/index%.html$", "/") + local abs = target_file + local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") return pandoc.MetaMap({ abs = pandoc.MetaString(abs), @@ -176,10 +182,10 @@ function prep_main_menu(rewrites, section, main_menu) }) end -function organize_subpages(site_url, output_dir, ref_file, pages) +function organize_subpages(site_url, ref_file, pages) for i = 1, #pages do local page = pages[i] - page.url = resolve_url(site_url, output_dir, ref_file, + page.url = resolve_url(site_url, ref_file, pandoc.utils.stringify(page.file_out)) end @@ -250,7 +256,6 @@ end function Meta(meta) meta.content_dir = meta.content_dir:gsub("/$", "") - meta.output_dir = meta.output_dir:gsub("/$", "") meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") meta.rewrites = meta.rewrites or pandoc.MetaMap({path = pandoc.MetaList({})}) @@ -258,19 +263,17 @@ function Meta(meta) meta.layout = resolve_layout(meta.layout) meta.section = resolve_section(meta.content_dir, meta.file_in) - meta.file_out = get_file_out(meta.rewrites, meta.content_dir, - meta.output_dir, meta.file_in) + meta.file_out = get_file_out(meta.rewrites, meta.content_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.relative_to) - meta.url = resolve_url(meta.site.url, meta.output_dir, meta.relative_to_out, - meta.file_out) + meta.url = resolve_url(meta.site.url, meta.relative_to_out, meta.file_out) if meta.preview ~= nil then - meta.preview = pandoc.utils.stringify(meta.preview) - meta.preview = meta.file_out:gsub("/index%.html$", "/" .. meta.preview) - meta.preview = resolve_url(meta.site.url, meta.output_dir, - meta.relative_to_out, meta.preview) + meta.preview = resolve_url(meta.site.url, meta.relative_to_out, + make_absolute( + pandoc.utils.stringify(meta.preview), + meta.file_out)) end meta.date = format_date(meta.date) @@ -286,16 +289,14 @@ function Meta(meta) if meta.page_type == "feed" then meta.page = pandoc.MetaMap({ - url = resolve_url(meta.site.url, meta.output_dir, - meta.relative_to_out, + url = resolve_url(meta.site.url, 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.relative_to_out, + url = resolve_url(meta.site.url, meta.relative_to_out, meta.file_out:gsub("%.html$", ".xml")) }) end @@ -307,7 +308,6 @@ function Meta(meta) if meta.pages then local pages, categories = organize_subpages(meta.site.url, - meta.output_dir, meta.relative_to_out, meta.pages) meta.pages = pages -- cgit v1.2.3-70-g09d2