blog

git clone https://git.ce9e.org/blog.git

commit
e9d599f58b2ce8d350006935ff55938036e62220
parent
affec02a66259064760a2cfda9e25be0aad88761
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-06-18 11:33
fix: use absolute URLs for links and images in feed

Diffstat

A filters/abs-urls.lua 30 ++++++++++++++++++++++++++++++

1 files changed, 30 insertions, 0 deletions


diff --git a/filters/abs-urls.lua b/filters/abs-urls.lua

@@ -0,0 +1,30 @@
   -1     1 local base_url = "https://blog.ce9e.org/"
   -1     2 
   -1     3 local function convert_relative_url(url)
   -1     4     local input_file = PANDOC_STATE.input_files[1]
   -1     5 
   -1     6     if url:sub(1, 4) == "http" then
   -1     7         return url
   -1     8     elseif input_file:sub(1, 5) == "build" then
   -1     9         return url
   -1    10     elseif url:sub(1, 1) == "/" then
   -1    11         return base_url .. url:sub(2)
   -1    12     else
   -1    13         local path = pandoc.path.directory(input_file)
   -1    14         path = pandoc.path.join({path, url})
   -1    15         path = pandoc.path.normalize(path)
   -1    16         path = path:gsub("[^/]+/%.%./", "")
   -1    17         path = path:gsub("^[^/]+/", "")
   -1    18         return base_url .. path
   -1    19     end
   -1    20 end
   -1    21 
   -1    22 function Link(el)
   -1    23     el.target = convert_relative_url(el.target)
   -1    24     return el
   -1    25 end
   -1    26 
   -1    27 function Image(el)
   -1    28     el.src = convert_relative_url(el.src)
   -1    29     return el
   -1    30 end