aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kavon <hawk@alexkavon.com>2023-11-27 17:52:06 -0500
committerAlexander Kavon <hawk@alexkavon.com>2023-11-27 17:52:06 -0500
commit21fb29d0eec71f3dd7c12e260af5925d452b238f (patch)
tree5252b9d0b07a0aa64de2b20680c0ef4283433143
parent1d05f918887e9ba4576149513e5df0bb57e6bd72 (diff)
template files for registration page, updated cwd handling, included cwd and config file path in conf struct
-rw-r--r--src/auth/routes.go4
-rw-r--r--src/conf/conf.go18
-rw-r--r--ui/pages/auth/register.tmpl.html16
-rw-r--r--ui/templates/base.tmpl.html (renamed from views/templates/main.tmpl.html)6
4 files changed, 37 insertions, 7 deletions
diff --git a/src/auth/routes.go b/src/auth/routes.go
index 796d123..4f161de 100644
--- a/src/auth/routes.go
+++ b/src/auth/routes.go
@@ -25,7 +25,7 @@ func Register(s *server.Server) http.HandlerFunc {
if err != nil {
log.Fatal(err)
}
- tmpl := template.Must(template.ParseFiles(cwd + "/views/templates/main.tmpl.html"))
- tmpl.Execute(w, nil)
+ tmpl := template.Must(template.ParseFiles(cwd+"/ui/templates/base.tmpl.html", cwd+"/ui/pages/auth/register.tmpl.html"))
+ tmpl.ExecuteTemplate(w, "base", nil)
}
}
diff --git a/src/conf/conf.go b/src/conf/conf.go
index 8abb8a8..969332a 100644
--- a/src/conf/conf.go
+++ b/src/conf/conf.go
@@ -9,6 +9,8 @@ import (
type (
Conf struct {
+ cwd string
+ path string
Db Db `toml:"database"`
Server Server `toml:"server"`
}
@@ -28,20 +30,22 @@ type (
func NewConf() *Conf {
- workingdir, err := os.Getwd()
+ cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
filepath := os.Getenv("NEWSSTAND_CONFIG_PATH")
if filepath == "" {
- filepath = workingdir + "/.newsstandrc.toml"
+ filepath = cwd + "/.newsstandrc.toml"
}
log.Printf("Config file path: %s", filepath)
c := Conf{
+ cwd,
+ filepath,
Db{},
Server{
- TemplatePath: workingdir + "/views",
+ TemplatePath: cwd + "/ui",
},
}
_, err = toml.DecodeFile(filepath, &c)
@@ -52,3 +56,11 @@ func NewConf() *Conf {
return &c
}
+
+func (c *Conf) GetCwd() string {
+ return c.cwd
+}
+
+func (c *Conf) GetPath() string {
+ return c.path
+}
diff --git a/ui/pages/auth/register.tmpl.html b/ui/pages/auth/register.tmpl.html
new file mode 100644
index 0000000..7dfd7aa
--- /dev/null
+++ b/ui/pages/auth/register.tmpl.html
@@ -0,0 +1,16 @@
+{{define "title"}}Register{{end}}
+
+{{define "main"}}
+ <h1>Registration</h1>
+ <form hx-post="/user">
+ <label>
+ Username
+ <input type="text" placeholder="username" />
+ </label>
+ <label>
+ Password
+ <input type="password" placeholder="password" />
+ </label>
+ <button type="submit">Register</button>
+ </form>
+{{end}}
diff --git a/views/templates/main.tmpl.html b/ui/templates/base.tmpl.html
index b6eeb51..4e28bc0 100644
--- a/views/templates/main.tmpl.html
+++ b/ui/templates/base.tmpl.html
@@ -1,10 +1,12 @@
+{{define "base"}}
<!DOCTYPE html>
<html lang="en">
<head>
- <title>newsstand.nyc</title>
+ <title>{{template "title" .}} | newsstand.nyc</title>
<script src="https://unpkg.com/htmx.org@1.9.9" integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX" crossorigin="anonymous"></script>
</head>
<body>
- <h1>Wello, Horld!</h1>
+ {{template "main" .}}
</body>
</html>
+{{end}}