template stuff polish

This commit is contained in:
Jill 2023-01-05 19:53:12 +03:00
parent ba18d2f0d9
commit ede1e7a217
10 changed files with 74 additions and 6 deletions

View File

@ -78,4 +78,15 @@ a:hover {
pre {
display: inline;
font-family: monospace;
}
.dir-header {
background-color: rgba(150, 150, 150, 0.15);
color: #999;
padding: 0.5em;
border-radius: 12px;
line-height: 1.2;
}
.dir-header a {
text-decoration: none;
}

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/style.css" />
<title>Account Management</title>
</head>
<body style="max-width: 800px; margin: auto; padding-top: 1em;">
<h1>Account Management</h1>
<i>hewwo</i>
</body>
</html>

View File

@ -42,8 +42,6 @@
</el>
</p>
</div>
<div class="dim">
Crystal <%= Crystal::VERSION %> <pre><%= Crystal::BUILD_COMMIT %></pre> running on <pre><%= System.hostname %></pre> for <%= CrystalGauntlet.uptime_s %>
</div>
<%= Templates.footer %>
</body>
</html>

View File

@ -7,7 +7,10 @@
<link rel="stylesheet" href="/style.css" />
<title>Level Reupload</title>
</head>
<body>
<body style="max-width: 800px; margin: auto; padding-top: 1em;">
<%= Templates.dir_header %>
<h1>Level Reupload</h1>
<%- if error -%>
<div>Error while uploading: <%= error %></div><br />
<%- elsif level_id -%>
@ -18,6 +21,7 @@
ID: <input type="text" id="level_id" name="level_id" />
<input type="submit" value="Submit" />
</form>
<br>
<i>Currently only vanilla servers are supported</i>
</body>
</html>

View File

@ -7,7 +7,10 @@
<link rel="stylesheet" href="/style.css" />
<title>Song Search</title>
</head>
<body>
<body style="max-width: 800px; margin: auto; padding-top: 1em;">
<%= Templates.dir_header %>
<h1>Song Search</h1>
<form action="/tools/song_search" method="post">
ID/Author/Title: <input type="text" id="query" name="query" />
<input type="submit" value="Submit" />

View File

@ -7,7 +7,9 @@
<link rel="stylesheet" href="/style.css" />
<title>Song Uploader</title>
</head>
<body>
<body style="max-width: 800px; margin: auto; padding-top: 1em;">
<%= Templates.dir_header %>
<h1>Song Upload</h1>
<%- if error -%>
<div>Error while uploading: <%= error %></div><br />
<%- elsif song_id -%>

View File

@ -20,6 +20,7 @@ require "./lib/songs"
require "./lib/ids"
require "./lib/level"
require "./lib/dailies"
require "./lib/templates"
if File.exists?(".env")
Dotenv.load

16
src/lib/templates.cr Normal file
View File

@ -0,0 +1,16 @@
module CrystalGauntlet::Templates
extend self
macro dir_header()
path_split = context.request.path.split('/')
"<div class='dir-header'>" + path_split.map_with_index { |v, i| "<a href='/#{path_split[1..i].join('/')}'>#{i == 0 ? "crystal-gauntlet" : v}</a>"}.join(" / ") + "</div>"
end
def footer()
%(
<div class="dim">
Crystal #{Crystal::VERSION} <pre>#{Crystal::BUILD_COMMIT}</pre> running on <pre>#{System.hostname}</pre> for #{CrystalGauntlet.uptime_s}
</div>
)
end
end

View File

@ -0,0 +1,14 @@
require "uri"
require "compress/gzip"
include CrystalGauntlet
CrystalGauntlet.template_endpoints["/#{config_get("general.append_path").as(String | Nil) || ""}accounts/accountManagement.php"] = ->(context : HTTP::Server::Context) {
context.response.headers.add("Location", "/accounts/")
context.response.status = HTTP::Status::MOVED_PERMANENTLY
}
CrystalGauntlet.template_endpoints["/accounts"] = ->(context : HTTP::Server::Context) {
context.response.content_type = "text/html"
ECR.embed("./public/template/account_management.ecr", context.response)
}

View File

@ -2,6 +2,11 @@ require "ecr"
include CrystalGauntlet
CrystalGauntlet.template_endpoints["/tools"] = ->(context : HTTP::Server::Context) {
context.response.headers.add("Location", "/")
context.response.status = HTTP::Status::TEMPORARY_REDIRECT
}
CrystalGauntlet.template_endpoints[""] = ->(context : HTTP::Server::Context) {
context.response.content_type = "text/html"
ECR.embed("./public/template/index.ecr", context.response)