From 93911faccb27ac11f3d4a1fdc098ebb6255d5612 Mon Sep 17 00:00:00 2001
From: Volpeon <git@volpeon.ink>
Date: Wed, 3 Aug 2022 16:23:32 +0200
Subject: Website gen adjustments

---
 scripts/metadata.lua      | 89 ++++++++++++++++++++++++-----------------------
 scripts/pages_content.lua | 27 ++++++++++++++
 scripts/subpages.lua      | 27 --------------
 3 files changed, 72 insertions(+), 71 deletions(-)
 create mode 100644 scripts/pages_content.lua
 delete mode 100644 scripts/subpages.lua

(limited to 'scripts')

diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index cb6c6e6..7d9206f 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -111,8 +111,8 @@ function process_pages(global, build, order, pages_by_id)
     local pages_date_desc = pandoc.List()
 
     if pages_by_id then
-        for _, page in pairs(pages_by_id) do
-            local p = process(global, build, page)
+        for _, p in pairs(pages_by_id) do
+            process(global, build, p)
             if not p.unlisted then
                 pages_all:insert(p)
                 if p.last_update then pages_date_desc:insert(p) end
@@ -133,19 +133,35 @@ function find_depth(meta)
 
     local depth = 0
 
-    if meta.pages then
-        for _, page in pairs(meta.pages) do
-            local p = find_depth(page)
-            if not p.unlisted then
-                local d = p.depth + 1
-                if d > depth then depth = d end
-            end
+    for _, p in pairs(meta.pages) do
+        find_depth(p)
+        if not p.unlisted then
+            local d = p.depth + 1
+            if d > depth then depth = d end
         end
     end
 
     meta.depth = depth
+end
 
-    return meta
+function resolve_urls(global, build, meta)
+    meta.url = resolve_url(global.site.url, build.file_out, meta.url)
+
+    if meta.feed then
+        if meta.file_out:match(".html$") then
+            meta.feed = {
+                url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")),
+            }
+        else
+            meta.page = {
+                url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")),
+            }
+        end
+    end
+
+    if meta.thumbnail then
+        meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail)
+    end
 end
 
 function d1_page_to_list_item(meta, p)
@@ -249,40 +265,20 @@ end
 
 function process(global, build, meta)
     meta.namespace = resolve_namespace(meta.namespace)
-    meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "")
+    meta.file_out = pandoc.utils.stringify(meta.file_out)
     meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev")
     meta.redirect = meta.url and true
-    meta.url = meta.url and pandoc.utils.stringify(meta.url)
-    meta.url = resolve_url(global.site.url, build.file_out, meta.url or meta.file_out)
-    meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or ""
+    meta.url = meta.url and pandoc.utils.stringify(meta.url) or meta.file_out
+    meta.title = meta.title and pandoc.utils.stringify(meta.title) or ""
     meta.slug = slug(meta.title)
-    meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork"
-    if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end
+    meta.schema_type = meta.schema_type and pandoc.utils.stringify(meta.schema_type) or "CreativeWork"
+    meta.list_order = meta.list_order and pandoc.utils.stringify(meta.list_order)
     meta.list_layout = prep_layout(meta.list_layout or "list")
-    if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end
-    if meta.position then meta.position = tonumber(pandoc.utils.stringify(meta.position)) end
+    meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit))
+    meta.position = meta.position and tonumber(pandoc.utils.stringify(meta.position))
+    meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out)
 
-    if meta.feed then
-        if meta.file_out:match(".html$") then
-            meta.feed = {
-                url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")),
-            }
-        else
-            meta.page = {
-                url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")),
-            }
-        end
-    end
-
-    if meta.thumbnail then
-        meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail),
-            meta.file_out)
-        meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail)
-    end
-
-    if meta.menus and meta.menus.main then
-        meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
-    end
+    resolve_urls(global, build, meta)
 
     meta.pages = process_pages(global, build, meta.list_order, meta.pages)
     meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth))
@@ -302,10 +298,6 @@ function process(global, build, meta)
     end
 
     meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd
-
-    meta.list = generate_list(meta)
-
-    return meta
 end
 
 function Meta(meta)
@@ -316,11 +308,20 @@ function Meta(meta)
 
         if suffix then
             build[suffix] = value
+            meta[key] = nil
         end
     end
 
     meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
 
     find_depth(meta)
-    return process(meta, build, meta)
+    process(meta, build, meta)
+
+    meta.list = generate_list(meta)
+
+    if meta.menus and meta.menus.main then
+        meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
+    end
+
+    return meta
 end
diff --git a/scripts/pages_content.lua b/scripts/pages_content.lua
new file mode 100644
index 0000000..b753b1e
--- /dev/null
+++ b/scripts/pages_content.lua
@@ -0,0 +1,27 @@
+local path = require 'pandoc.path'
+
+local namespace = ''
+local siteUrl = ''
+
+function meta(meta)
+    namespace = pandoc.utils.stringify(meta.namespace.full)
+    siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
+end
+
+function image(el)
+    if path.is_relative(el.src) and not el.src:match("^https?://") then
+        el.src = siteUrl .. path.join({ namespace, el.src })
+    end
+
+    return el
+end
+
+function link(el)
+    if path.is_relative(el.target) and not el.target:match("^https?://") then
+        el.target = siteUrl .. path.join({ namespace, el.target })
+    end
+
+    return el
+end
+
+return { { Meta = meta }, { Image = image, Link = link } }
diff --git a/scripts/subpages.lua b/scripts/subpages.lua
deleted file mode 100644
index b753b1e..0000000
--- a/scripts/subpages.lua
+++ /dev/null
@@ -1,27 +0,0 @@
-local path = require 'pandoc.path'
-
-local namespace = ''
-local siteUrl = ''
-
-function meta(meta)
-    namespace = pandoc.utils.stringify(meta.namespace.full)
-    siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
-end
-
-function image(el)
-    if path.is_relative(el.src) and not el.src:match("^https?://") then
-        el.src = siteUrl .. path.join({ namespace, el.src })
-    end
-
-    return el
-end
-
-function link(el)
-    if path.is_relative(el.target) and not el.target:match("^https?://") then
-        el.target = siteUrl .. path.join({ namespace, el.target })
-    end
-
-    return el
-end
-
-return { { Meta = meta }, { Image = image, Link = link } }
-- 
cgit v1.2.3-70-g09d2