From b82e138c4dca1b072ae49856f3effcd335e07b9e Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Wed, 6 Dec 2023 09:12:49 +0100 Subject: [PATCH] added content to about and contact page and added main-handler to achive spa-functionality --- handlers/main_handler.go | 28 ++++++++++++++++++++ main.go | 1 + templates/about.html | 13 ++++++++++ templates/base.html | 2 +- templates/contact.html | 56 ++++++++++++++++++++++++++++++++++++++++ templates/header.html | 6 ++--- 6 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 handlers/main_handler.go diff --git a/handlers/main_handler.go b/handlers/main_handler.go new file mode 100644 index 0000000..06a3821 --- /dev/null +++ b/handlers/main_handler.go @@ -0,0 +1,28 @@ +package handlers + +import ( + "embed" + "html/template" + "log" + "net/http" +) + +// MainHandler +func MainHandler(content embed.FS) http.HandlerFunc { + log.Print("MainHandler called") + return func(w http.ResponseWriter, r *http.Request) { + tmpl, err := template.ParseFS(content, "templates/main.html", "templates/monsterForm.html", "templates/monster.html", "templates/monsterTable.html") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{ + "Title": "Dungeons & Dragons Monster Generator", + }) + if err != nil { + log.Printf("Template execution error: %v\n", err) + http.Error(w, err.Error(), http.StatusInternalServerError) + } + } +} diff --git a/main.go b/main.go index 79d9633..a990799 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ func main() { http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename)) http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content)))) http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters)) + http.HandleFunc("/main", handlers.MainHandler(content)) http.HandleFunc("/about", handlers.AboutHandler(content)) http.HandleFunc("/contact", handlers.ContactHandler(content)) http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters)) diff --git a/templates/about.html b/templates/about.html index cff355b..9d29c17 100644 --- a/templates/about.html +++ b/templates/about.html @@ -1,2 +1,15 @@ {{ define "about" }} +
+
+
+
+

About Us

+
+
+

Welcome to the Dungeons and Dragons Monster Generator website! We are a team of enthusiasts...

+
+
+
+
+ {{ end }} diff --git a/templates/base.html b/templates/base.html index f94677e..7d8e18c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -17,7 +17,7 @@
{{ template "header" . }}
-
+
{{ template "main" . }}
diff --git a/templates/contact.html b/templates/contact.html index 3e76614..4b1dbea 100644 --- a/templates/contact.html +++ b/templates/contact.html @@ -1,2 +1,58 @@ {{ define "contact" }} +
+
+
+
+

Contact Us

+
+
+ +
+

Our Contact Information

+

You can reach us through the following channels:

+
    +
  • Email: example@example.com
  • +
  • Phone: +123456789
  • + +
+
+ +
+

Contact Form

+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
{{ end }} diff --git a/templates/header.html b/templates/header.html index dcaa1e5..fb33787 100644 --- a/templates/header.html +++ b/templates/header.html @@ -11,15 +11,15 @@