From 4559f2b67e28e6a0fd4e692129e000bd6e5b7081 Mon Sep 17 00:00:00 2001 From: luneko Date: Thu, 30 Dec 2021 23:49:35 +0100 Subject: [PATCH] added html and template creation --- html/kotatsu.html | 11 +++++++++++ src/kotatsu.cr | 21 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 html/kotatsu.html diff --git a/html/kotatsu.html b/html/kotatsu.html new file mode 100644 index 0000000..8a8c576 --- /dev/null +++ b/html/kotatsu.html @@ -0,0 +1,11 @@ + + + + + --KOTATSU_TITLE-- + + +

--KOTATSU_TITLE--

+ --KOTATSU_SERVICES-- + + \ No newline at end of file diff --git a/src/kotatsu.cr b/src/kotatsu.cr index d493fe7..0479291 100644 --- a/src/kotatsu.cr +++ b/src/kotatsu.cr @@ -96,6 +96,21 @@ module Kotatsu 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 + "#{services[i][0]}
" + i+=1 + end + content = content.sub("--KOTATSU_SERVICES--", services_c) + + return content + end + # -- PARSER -- OptionParser.parse do |parser| @@ -181,10 +196,12 @@ module Kotatsu #Reads config file c_version, c_port, c_title, c_services = readConfig() + webcontent = makeContent(c_title, c_services) + #Run http server webserv = HTTP::Server.new do |context| - context.response.content_type = "text/plain" - context.response.print "Running kotatsu #{VERSION}" + context.response.content_type = "text/html" + context.response << webcontent end webaddr = webserv.bind_tcp c_port puts "Started kotatsu webserver on #{webaddr}"