summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorThomas Letan <lthms@soap.coffee>2020-02-15 15:38:47 +0100
committerThomas Letan <lthms@soap.coffee>2020-02-15 15:41:53 +0100
commitd173e77712917fdb9f76995cc9ac9b857965aaf9 (patch)
treeafc78e1cefc42ec7805a3d32e075ead603b8da5c /plugins
parentSelf hosting of Fira Sans and various small fixes (diff)
Make the website 3rd-party free and improve loading performance
- Use webp in place of a regular png - Lazy loading of CSS files (compatible with javascript-less browsers) - KaTeX in place of MathJax - Minified CSS (using sass) - Vendoring fonts, scripts, and CSS.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/site-prefix.lua54
1 files changed, 29 insertions, 25 deletions
diff --git a/plugins/site-prefix.lua b/plugins/site-prefix.lua
index 6c7f12a..a8629fc 100644
--- a/plugins/site-prefix.lua
+++ b/plugins/site-prefix.lua
@@ -1,32 +1,36 @@
-site_url = config["site_url"]
+function fix_urls (links, attr, prefix_url)
+ index, link = next(links)
-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
+ while index do
+ href = HTML.get_attribute(link, attr)
-links = HTML.select(page, "a")
+ if href then
+ -- remove prefix sometimes introduced by org
+ href = Regex.replace(href, "^file://", "")
-index, link = next(links)
+ -- Check if URL starts with a leading "/"
+ if Regex.match(href, "^/") then
+ -- Remove leading slashes
+ href = Regex.replace(href, "^/*", "")
+ href = prefix_url .. href
+ HTML.set_attribute(link, attr, href)
+ end
+ end
+ index, link = next(links, index)
+ end
+end
-while index do
- href = HTML.get_attribute(link, "href")
+prefix_url = config["prefix_url"]
- if href then
- -- remove prefix sometimes introduced by org
- href = Regex.replace(href, "^file://", "")
+if not prefix_url then
+ prefix_url = ""
+end
- -- 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)
+if not Regex.match(prefix_url, "(.*)/$") then
+ prefix_url = prefix_url .. "/"
end
+
+fix_urls(HTML.select(page, "a"), "href", prefix_url)
+fix_urls(HTML.select(page, "link"), "href", prefix_url)
+fix_urls(HTML.select(page, "img"), "src", prefix_url)
+fix_urls(HTML.select(page, "script"), "src", prefix_url) \ No newline at end of file