-
Notifications
You must be signed in to change notification settings - Fork 1
/
reluax.luax
94 lines (83 loc) · 2.61 KB
/
reluax.luax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
local Common = require("common")
local Navbar = require("components.navbar")
local Footer = require("components.footer")
local AnimatedBg = require("components.animated_bg")
local Home = require("pages.home")
local Projects = require("pages.projects")
local Games = require("pages.games")
local Contact = require("pages.contact")
local Blogpost = require("pages.blogpost")
local Blog = require("pages.blog")
local NotFound = require("not_found")
local blogposts = require("blog.posts")
math.randomseed(os.time())
local wrap_component = function(component)
return
<Common>
<Navbar />
<div class="back-shadows"></div>
<div id="app-main">
{$ component $}
<AnimatedBg />
</div>
<Footer />
</Common>
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"
end
if reluax.url_matches('/r/{slug}', path) then
local slug = reluax.url_extract('/r/{slug}', path).slug
local redirect = redirects[slug]
if redirect then
local headers = {
["Location"] = redirect
}
local body = <a>You are being redirected...</a>
return 301, reluax.headers(body, headers)
end
elseif path == '/' then
return 200, wrap_component(<Home />)
elseif path == '/projects' then
return 200, wrap_component(<Projects />)
elseif path == '/games' then
return 200, wrap_component(<Games />)
elseif path == '/contact' then
return 200, wrap_component(<Contact />)
elseif path == '/blog' then
return 200, wrap_component(<Blog />)
elseif reluax.url_matches('/blog/{slug}', path) then
local slug = reluax.url_extract('/blog/{slug}', path).slug
-- blogposts is a list of blogposts, with the slug a property of each
local post = nil
for _, p in ipairs(blogposts) do
if p.slug == slug then
post = p
break
end
end
if post then
local article =
<Common title={post.title} description={post.description}>
<Navbar />
<div class="back-shadows"></div>
<div id="app-main">
<Blogpost post={post} />
<AnimatedBg />
</div>
<Footer />
</Common>
return 200, article
end
end
return 404, NotFound()
end
return {
name = "duckonaut.dev",
route = route
}