From 3cf21a28f3c64b69e10dec76869f23e7d0bd7933 Mon Sep 17 00:00:00 2001 From: Stanisław Zagórowski Date: Mon, 29 Jan 2024 17:29:07 +0100 Subject: site: simplify redirects --- reluax.luax | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/reluax.luax b/reluax.luax index 034d408..5b05eb7 100644 --- a/reluax.luax +++ b/reluax.luax @@ -15,11 +15,6 @@ local blogposts = require("blog.posts") math.randomseed(os.time()) -local redirects = { - { slug = "mrfinalboss", url = "https://jellingfish-games.itch.io/mr-final-boss" }, - { slug = "bumblingbuilders", url = "https://oroshibu.itch.io/bumbling-builders" } -} - local wrap_component = function(component) return @@ -33,6 +28,11 @@ local wrap_component = function(component) end +local redirects = { + ["mrfinalboss"] = "https://jellingfish-games.itch.io/mr-final-boss", + ["bumblingbuilders"] = "https://oroshibu.itch.io/bumbling-builders" +} + local route = function(path, method, headers, body) if method ~= 'GET' then return 405, "Method not allowed" @@ -40,16 +40,10 @@ local route = function(path, method, headers, body) if reluax.url_matches('/r/{slug}', path) then local slug = reluax.url_extract('/r/{slug}', path).slug - local redirect = nil - for _, r in ipairs(redirects) do - if r.slug == slug then - redirect = r - break - end - end + local redirect = redirects[slug] if redirect then local headers = { - ["Location"] = redirect.url + ["Location"] = redirect } local body = You are being redirected... return 301, reluax.headers(body, headers) -- cgit v1.3.1