added html and template creation

This commit is contained in:
2021-12-30 23:49:35 +01:00
parent f21da31561
commit 4559f2b67e
2 changed files with 30 additions and 2 deletions

11
html/kotatsu.html Normal file
View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>--KOTATSU_TITLE--</title>
</head>
<body>
<h1>--KOTATSU_TITLE--</h1>
--KOTATSU_SERVICES--
</body>
</html>

View File

@@ -96,6 +96,21 @@ module Kotatsu
end end
end end
def self.makeContent(title, services)
content = File.read("./html/kotatsu.html")
content = content.gsub("--KOTATSU_TITLE--", title)
services_c = String.new
i = 0
while services.size > i
services_c = services_c + "<a href=\"#{services[i][1]}\">#{services[i][0]}</a><br>"
i+=1
end
content = content.sub("--KOTATSU_SERVICES--", services_c)
return content
end
# -- PARSER -- # -- PARSER --
OptionParser.parse do |parser| OptionParser.parse do |parser|
@@ -181,10 +196,12 @@ module Kotatsu
#Reads config file #Reads config file
c_version, c_port, c_title, c_services = readConfig() c_version, c_port, c_title, c_services = readConfig()
webcontent = makeContent(c_title, c_services)
#Run http server #Run http server
webserv = HTTP::Server.new do |context| webserv = HTTP::Server.new do |context|
context.response.content_type = "text/plain" context.response.content_type = "text/html"
context.response.print "Running kotatsu #{VERSION}" context.response << webcontent
end end
webaddr = webserv.bind_tcp c_port webaddr = webserv.bind_tcp c_port
puts "Started kotatsu webserver on #{webaddr}" puts "Started kotatsu webserver on #{webaddr}"