diff options
| author | Volpeon <git@volpeon.ink> | 2021-04-21 17:12:50 +0200 |
|---|---|---|
| committer | Volpeon <git@volpeon.ink> | 2021-04-21 17:12:50 +0200 |
| commit | 2b58f2589efb48f7df112a2e175ce28b52f2f8f7 (patch) | |
| tree | 397eaf39cf2ce50ba1f9abbfa9ecf133386549f2 /scripts/metadata_filter.lua | |
| parent | Less intensive project card shadow (diff) | |
| download | volpeon.ink-2b58f2589efb48f7df112a2e175ce28b52f2f8f7.tar.gz volpeon.ink-2b58f2589efb48f7df112a2e175ce28b52f2f8f7.tar.bz2 volpeon.ink-2b58f2589efb48f7df112a2e175ce28b52f2f8f7.zip | |
Small build script and design improvements
Diffstat (limited to 'scripts/metadata_filter.lua')
| -rw-r--r-- | scripts/metadata_filter.lua | 48 |
1 files changed, 24 insertions, 24 deletions
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) | |||
| 101 | return str | 101 | return str |
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | function get_file_out(rewrites, content_dir, output_dir, file_in) | 104 | function get_file_out(rewrites, content_dir, file_in) |
| 105 | local file_out = file_in:gsub("^" .. content_dir, ""):gsub("%.md$", ".html") | 105 | local file_out = file_in:gsub("^" .. content_dir, ""):gsub("%.md$", ".html") |
| 106 | 106 | ||
| 107 | if file_out:match(".html$") and not file_out:match("/index%.html$") then | 107 | 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) | |||
| 110 | 110 | ||
| 111 | file_out = apply_path_rewrites(rewrites, file_out) | 111 | file_out = apply_path_rewrites(rewrites, file_out) |
| 112 | 112 | ||
| 113 | return pandoc.MetaString(output_dir .. file_out) | 113 | return pandoc.MetaString(file_out) |
| 114 | end | 114 | end |
| 115 | 115 | ||
| 116 | function resolve_url(site_url, output_dir, ref_file, target_file) | 116 | function make_absolute(rel, base) |
| 117 | return | ||
| 118 | rel:find("^/") ~= nil and rel or base:gsub("^(.*)/.-$", "%1") .. "/" .. | ||
| 119 | rel | ||
| 120 | end | ||
| 121 | |||
| 122 | function resolve_url(site_url, ref_file, target_file) | ||
| 123 | target_file = target_file:gsub("/index%.html$", "/") | ||
| 124 | |||
| 117 | local ref_base_dir = ref_file:gsub("^(.*)/.-$", "%1") | 125 | local ref_base_dir = ref_file:gsub("^(.*)/.-$", "%1") |
| 118 | local abs = target_file:gsub("^" .. output_dir, ""):gsub("/index%.html$", | 126 | local abs = target_file |
| 119 | "/") | 127 | local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") |
| 120 | local rel = | ||
| 121 | relative_to(ref_base_dir, target_file):gsub("/index%.html$", "/") | ||
| 122 | 128 | ||
| 123 | return pandoc.MetaMap({ | 129 | return pandoc.MetaMap({ |
| 124 | abs = pandoc.MetaString(abs), | 130 | abs = pandoc.MetaString(abs), |
| @@ -176,10 +182,10 @@ function prep_main_menu(rewrites, section, main_menu) | |||
| 176 | }) | 182 | }) |
| 177 | end | 183 | end |
| 178 | 184 | ||
| 179 | function organize_subpages(site_url, output_dir, ref_file, pages) | 185 | function organize_subpages(site_url, ref_file, pages) |
| 180 | for i = 1, #pages do | 186 | for i = 1, #pages do |
| 181 | local page = pages[i] | 187 | local page = pages[i] |
| 182 | page.url = resolve_url(site_url, output_dir, ref_file, | 188 | page.url = resolve_url(site_url, ref_file, |
| 183 | pandoc.utils.stringify(page.file_out)) | 189 | pandoc.utils.stringify(page.file_out)) |
| 184 | end | 190 | end |
| 185 | 191 | ||
| @@ -250,7 +256,6 @@ end | |||
| 250 | 256 | ||
| 251 | function Meta(meta) | 257 | function Meta(meta) |
| 252 | meta.content_dir = meta.content_dir:gsub("/$", "") | 258 | meta.content_dir = meta.content_dir:gsub("/$", "") |
| 253 | meta.output_dir = meta.output_dir:gsub("/$", "") | ||
| 254 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") | 259 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") |
| 255 | meta.rewrites = meta.rewrites or | 260 | meta.rewrites = meta.rewrites or |
| 256 | pandoc.MetaMap({path = pandoc.MetaList({})}) | 261 | pandoc.MetaMap({path = pandoc.MetaList({})}) |
| @@ -258,19 +263,17 @@ function Meta(meta) | |||
| 258 | meta.layout = resolve_layout(meta.layout) | 263 | meta.layout = resolve_layout(meta.layout) |
| 259 | meta.section = resolve_section(meta.content_dir, meta.file_in) | 264 | meta.section = resolve_section(meta.content_dir, meta.file_in) |
| 260 | 265 | ||
| 261 | meta.file_out = get_file_out(meta.rewrites, meta.content_dir, | 266 | meta.file_out = get_file_out(meta.rewrites, meta.content_dir, meta.file_in) |
| 262 | meta.output_dir, meta.file_in) | ||
| 263 | if meta.relative_to == nil then meta.relative_to = meta.file_in end | 267 | if meta.relative_to == nil then meta.relative_to = meta.file_in end |
| 264 | meta.relative_to_out = get_file_out(meta.rewrites, meta.content_dir, | 268 | meta.relative_to_out = get_file_out(meta.rewrites, meta.content_dir, |
| 265 | meta.output_dir, meta.relative_to) | 269 | meta.relative_to) |
| 266 | 270 | ||
| 267 | meta.url = resolve_url(meta.site.url, meta.output_dir, meta.relative_to_out, | 271 | meta.url = resolve_url(meta.site.url, meta.relative_to_out, meta.file_out) |
| 268 | meta.file_out) | ||
| 269 | if meta.preview ~= nil then | 272 | if meta.preview ~= nil then |
| 270 | meta.preview = pandoc.utils.stringify(meta.preview) | 273 | meta.preview = resolve_url(meta.site.url, meta.relative_to_out, |
| 271 | meta.preview = meta.file_out:gsub("/index%.html$", "/" .. meta.preview) | 274 | make_absolute( |
| 272 | meta.preview = resolve_url(meta.site.url, meta.output_dir, | 275 | pandoc.utils.stringify(meta.preview), |
| 273 | meta.relative_to_out, meta.preview) | 276 | meta.file_out)) |
| 274 | end | 277 | end |
| 275 | 278 | ||
| 276 | meta.date = format_date(meta.date) | 279 | meta.date = format_date(meta.date) |
| @@ -286,16 +289,14 @@ function Meta(meta) | |||
| 286 | 289 | ||
| 287 | if meta.page_type == "feed" then | 290 | if meta.page_type == "feed" then |
| 288 | meta.page = pandoc.MetaMap({ | 291 | meta.page = pandoc.MetaMap({ |
| 289 | url = resolve_url(meta.site.url, meta.output_dir, | 292 | url = resolve_url(meta.site.url, meta.relative_to_out, |
| 290 | meta.relative_to_out, | ||
| 291 | meta.file_out:gsub("%.xml$", ".html")) | 293 | meta.file_out:gsub("%.xml$", ".html")) |
| 292 | }) | 294 | }) |
| 293 | end | 295 | end |
| 294 | 296 | ||
| 295 | if meta.create_feed then | 297 | if meta.create_feed then |
| 296 | meta.feed = pandoc.MetaMap({ | 298 | meta.feed = pandoc.MetaMap({ |
| 297 | url = resolve_url(meta.site.url, meta.output_dir, | 299 | url = resolve_url(meta.site.url, meta.relative_to_out, |
| 298 | meta.relative_to_out, | ||
| 299 | meta.file_out:gsub("%.html$", ".xml")) | 300 | meta.file_out:gsub("%.html$", ".xml")) |
| 300 | }) | 301 | }) |
| 301 | end | 302 | end |
| @@ -307,7 +308,6 @@ function Meta(meta) | |||
| 307 | 308 | ||
| 308 | if meta.pages then | 309 | if meta.pages then |
| 309 | local pages, categories = organize_subpages(meta.site.url, | 310 | local pages, categories = organize_subpages(meta.site.url, |
| 310 | meta.output_dir, | ||
| 311 | meta.relative_to_out, | 311 | meta.relative_to_out, |
| 312 | meta.pages) | 312 | meta.pages) |
| 313 | meta.pages = pages | 313 | meta.pages = pages |
