diff --git a/internal/api/project_handler.go b/internal/api/project_handler.go index 0dff92e..e8869f4 100644 --- a/internal/api/project_handler.go +++ b/internal/api/project_handler.go @@ -3,6 +3,7 @@ package api import ( "database/sql" "duhweb/internal/store" + "fmt" "html/template" "net/http" ) @@ -20,25 +21,35 @@ func (h *ProjectHandler) Render(w http.ResponseWriter, tmpl string, data interfa } func NewProjectHandler(db *sql.DB) *ProjectHandler { + tmpl := template.Must(template.New("").ParseGlob("views/*.html")) + template.Must(tmpl.ParseGlob("views/partials/*.html")) + return &ProjectHandler{ - Templates: template.Must(template.ParseGlob("views/*.html")), + Templates: tmpl, ProjectStore: store.NewSQLiteProjectStore(db), } } func (h *ProjectHandler) InitPage(w http.ResponseWriter, r *http.Request) { - h.Render(w, "index", nil) -} - -func (h *ProjectHandler) AboutPage(w http.ResponseWriter, r *http.Request) { - h.Render(w, "about", nil) + var hxRequest = r.Header.Get("HX-Request") + if hxRequest != "true" { + h.Render(w, "index", nil) + return + } + h.Render(w, "about-partial", nil) } func (h *ProjectHandler) ProjectsPage(w http.ResponseWriter, r *http.Request) { + var hxRequest = r.Header.Get("HX-Request") + fmt.Println(hxRequest) projects, err := h.ProjectStore.GetAllProjects() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - h.Render(w, "projects", projects) + if hxRequest != "true" { + h.Render(w, "projects", projects) + return + } + h.Render(w, "projects-partial", projects) } diff --git a/internal/routes/routes.go b/internal/routes/routes.go index 4f7542b..ecc1237 100644 --- a/internal/routes/routes.go +++ b/internal/routes/routes.go @@ -10,7 +10,6 @@ func SetupRoutes(app *app.Application) *chi.Mux { r := chi.NewRouter() r.Get("/", app.ProjectHandler.InitPage) - r.Get("/about", app.ProjectHandler.AboutPage) r.Get("/projects", app.ProjectHandler.ProjectsPage) return r -} \ No newline at end of file +} diff --git a/views/footer.html b/views/footer.html new file mode 100644 index 0000000..8b30d8c --- /dev/null +++ b/views/footer.html @@ -0,0 +1,28 @@ +{{ block "footer" .}} + +{{ end }} diff --git a/views/header.html b/views/header.html new file mode 100644 index 0000000..f6f332f --- /dev/null +++ b/views/header.html @@ -0,0 +1,33 @@ +{{ block "header" .}} +
+ +
+{{ end }} diff --git a/views/index.html b/views/index.html index bc8a862..e7f22d0 100644 --- a/views/index.html +++ b/views/index.html @@ -11,159 +11,13 @@ - -
- -
- - - -
{{ template "about" . }}
- - - + + {{ template "header" }} + +
{{ template "about-partial" . }}
+ + {{ template "footer" }} - - + {{ template "script" }} -{{ end }} {{ block "about" . }} - -
-

- Hi, I'm Your Name -

-

- A [Your Role] who loves building - [something about what you do]. -

-
- View Projects - Contact Me -
-
- - -
-

About Me

-

- I’m a [Your Profession] with experience in [key skills]. I enjoy solving - problems, learning new technologies, and building applications that make an - impact. Currently exploring - Go, - htmx, and modern web tools. -

-
-{{ end }} {{ block "projects" . }} -

Projects

-{{ range . }} {{ template "project" . }} {{ end}} {{ end }} {{ block "project" . -}} -
- {{ .Title }} - - {{ .Description }} -
{{ end }} diff --git a/views/partials/about-partial.html b/views/partials/about-partial.html new file mode 100644 index 0000000..d093d4d --- /dev/null +++ b/views/partials/about-partial.html @@ -0,0 +1,41 @@ +{{ block "about-partial" . }} + +
+

+ Hi, I'm Your Name +

+

+ A [Your Role] who loves building + [something about what you do]. +

+
+ View Projects + Contact Me +
+
+ + +
+

About Me

+

+ I’m a [Your Profession] with experience in [key skills]. I enjoy solving + problems, learning new technologies, and building applications that make an + impact. Currently exploring + Go, + htmx, and modern web tools. +

+
+{{ end }} diff --git a/views/partials/projects-partial.html b/views/partials/projects-partial.html new file mode 100644 index 0000000..061bb67 --- /dev/null +++ b/views/partials/projects-partial.html @@ -0,0 +1,9 @@ +{{ block "projects-partial" . }} +

Projects

+{{ range . }} {{ template "project-partial-range" . }} {{ end}} {{ end }} {{ +block "project-partial-range" . }} +
+ {{ .Title }} - + {{ .Description }} +
+{{ end }} diff --git a/views/projects.html b/views/projects.html new file mode 100644 index 0000000..aa0cf7f --- /dev/null +++ b/views/projects.html @@ -0,0 +1,23 @@ +{{ block "projects" . }} + + + + + + My CV Website + + + + + + + + {{ template "header" }} + +
{{ template "projects-partial" .}}
+ + {{ template "footer" }} + + {{ template "script" }} + +{{ end }} diff --git a/views/script.html b/views/script.html new file mode 100644 index 0000000..01d4c9a --- /dev/null +++ b/views/script.html @@ -0,0 +1,35 @@ +{{ block "script" .}} + +{{ end }}