summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/site-prefix.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/site-prefix.lua b/plugins/site-prefix.lua
new file mode 100644
index 0000000..e64f839
--- /dev/null
+++ b/plugins/site-prefix.lua
@@ -0,0 +1,28 @@
+site_url = config["site_url"]
+
+if not site_url then
+ Log.warning("site_url is not configured, using default")
+ site_url = ""
+end
+
+if not Regex.match(site_url, "(.*)/$") then
+ site_url = site_url .. "/"
+end
+
+links = HTML.select(page, "a")
+
+index, link = next(links)
+
+while index do
+ href = HTML.get_attribute(link, "href")
+ if href then
+ -- Check if URL starts with a leading "/"
+ if Regex.match(href, "^/") then
+ -- Remove leading slashes
+ href = Regex.replace(href, "^/*", "")
+ href = site_url .. href
+ HTML.set_attribute(link, "href", href)
+ end
+ end
+ index, link = next(links, index)
+end