commit 9f595558b6207c368d3cb2a4b0f39ac45be99436 Author: Keyemail Date: Sat Jul 6 02:04:33 2024 -0700 Started Go; Added Home, About diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebfa0c2 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# MBot Website + +The website that provides an explanation to MBot! There will be more future updates for this website but for now it basically just shows off the cool things it can do. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c45fa15 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module mbot + +go 1.22.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..a38232c --- /dev/null +++ b/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "net/http" + "os" + "log" + "html/template" +) + +type Index struct { + Title string +} + +var data = &Index { + Title: "Website", +} + +func aboutHandler(w http.ResponseWriter, req *http.Request) { + templates := template.Must(template.ParseFiles( + "src/index.tmpl", + "src/pages/about.tmpl", + "src/components/navbar.tmpl", + "src/components/footer.tmpl", + )) + + err := templates.ExecuteTemplate(w, "base", data) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +func indexHandler(w http.ResponseWriter, req *http.Request) { + templates := template.Must(template.ParseFiles( + "src/index.tmpl", + "src/pages/home.tmpl", + "src/components/navbar.tmpl", + "src/components/footer.tmpl", + )) + + err := templates.ExecuteTemplate(w, "base", data) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +func main() { + if _, err := os.Stat("src/index.tmpl"); os.IsNotExist(err) { + log.Fatal("Template file does not exist:\n", err) + } + + fs := http.FileServer(http.Dir("./src/")) + http.Handle("/src/", http.StripPrefix("/src/", fs)) + + port := ":3939" + + http.HandleFunc("/", indexHandler) + http.HandleFunc("/about", aboutHandler) + + log.Println("Server running at http://localhost" + port) + http.ListenAndServe(port, nil) +} diff --git a/src/components/footer.tmpl b/src/components/footer.tmpl new file mode 100644 index 0000000..11de250 --- /dev/null +++ b/src/components/footer.tmpl @@ -0,0 +1,5 @@ +{{ define "footer" }} + +{{ end }} diff --git a/src/components/navbar.tmpl b/src/components/navbar.tmpl new file mode 100644 index 0000000..c419117 --- /dev/null +++ b/src/components/navbar.tmpl @@ -0,0 +1,16 @@ +{{ define "navbar" }} + +{{ end }} diff --git a/src/index.tmpl b/src/index.tmpl new file mode 100644 index 0000000..1e0e638 --- /dev/null +++ b/src/index.tmpl @@ -0,0 +1,17 @@ +{{ define "base" }} + + + + {{ template "head" . }} + + + {{ .Title }} + + + + {{ template "navbar" . }} + {{ template "body" . }} + {{ template "footer" . }} + + +{{ end }} diff --git a/src/pages/about.tmpl b/src/pages/about.tmpl new file mode 100644 index 0000000..3af316d --- /dev/null +++ b/src/pages/about.tmpl @@ -0,0 +1,12 @@ + + {{ define "head" }} + + {{ end }} + + + {{ define "body" }} +
+

About page!

+
+ {{ end }} + diff --git a/src/pages/home.tmpl b/src/pages/home.tmpl new file mode 100644 index 0000000..51d1b78 --- /dev/null +++ b/src/pages/home.tmpl @@ -0,0 +1,12 @@ + + {{ define "head" }} + + {{ end }} + + + {{ define "body" }} +
+

Home page!

+
+ {{ end }} + diff --git a/src/styles/about.css b/src/styles/about.css new file mode 100644 index 0000000..83e5502 --- /dev/null +++ b/src/styles/about.css @@ -0,0 +1,5 @@ +header { + h1 { + margin-top: 30px; + } +} diff --git a/src/styles/home.css b/src/styles/home.css new file mode 100644 index 0000000..83e5502 --- /dev/null +++ b/src/styles/home.css @@ -0,0 +1,5 @@ +header { + h1 { + margin-top: 30px; + } +} diff --git a/src/styles/main.css b/src/styles/main.css new file mode 100644 index 0000000..6169412 --- /dev/null +++ b/src/styles/main.css @@ -0,0 +1,43 @@ +* { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +body { + display: flex; + flex-direction: column; + justify-content: space-between; + max-width: 1920px; + margin: auto; + padding: 20px; + min-height: 100vh; +} + +a { + color: inherit; + text-decoration: none; +} + +nav { + display: flex; + align-items: center; + justify-content: space-between; + + ul { + list-style: none; + float: right; + + li { + display: inline; + cursor: pointer; + margin-left: 10px; + } + } +} + +footer { + margin-top: auto; + width: 100%; + text-align: center; +}