From 7798930145d2c5c0e715c13bf13a7ef2634aaaf2 Mon Sep 17 00:00:00 2001 From: Elias Kohout Date: Thu, 2 Jan 2025 15:13:13 +0100 Subject: [PATCH] move templates to web dir --- cmd/frontend/main.go | 2 +- internal/routes/Index.go | 4 ++-- internal/routes/UpSearch.go | 4 ++-- {templates => web/templates}/article.html | 0 {templates => web/templates}/layout.html | 0 5 files changed, 5 insertions(+), 5 deletions(-) rename {templates => web/templates}/article.html (100%) rename {templates => web/templates}/layout.html (100%) diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index 3514d33..f09f979 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -12,7 +12,7 @@ func main() { http.HandleFunc("POST /up/search", routes.UpSearch) // serve files from the "static" directory - fs := http.FileServer(http.Dir("./static")) + fs := http.FileServer(http.Dir("web/static")) http.Handle("GET /static/", http.StripPrefix("/", fs)) // start server diff --git a/internal/routes/Index.go b/internal/routes/Index.go index 7b005dc..ca79d06 100644 --- a/internal/routes/Index.go +++ b/internal/routes/Index.go @@ -17,7 +17,7 @@ func (ord articleDateOrder) Weight(a *model.Article) int { // List the latest articles using the base template. func Index(w http.ResponseWriter, req *http.Request) { // retrieve from repo - fds, err := data.NewFileDatastore("./persistence/spiegel100.json") + fds, err := data.NewFileDatastore("persistence/spiegel100.json") if err != nil { http.Error(w, "Failed to load datastore", http.StatusInternalServerError); return; } repo, err := data.NewDefaultRepository[*model.Article](fds, "article") if err != nil { http.Error(w, "Failed to create repository", http.StatusInternalServerError); return; } @@ -36,7 +36,7 @@ func Index(w http.ResponseWriter, req *http.Request) { } // render template - t := template.Must(template.ParseFiles("templates/article.html", "templates/layout.html")) + t := template.Must(template.ParseFiles("web/templates/article.html", "web/templates/layout.html")) err = t.ExecuteTemplate(w, "base", articleVMs) if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; } } diff --git a/internal/routes/UpSearch.go b/internal/routes/UpSearch.go index 0105216..63fa390 100644 --- a/internal/routes/UpSearch.go +++ b/internal/routes/UpSearch.go @@ -40,7 +40,7 @@ func UpSearch(w http.ResponseWriter, req *http.Request) { } // retrieve from repo - fds, _ := data.NewFileDatastore("./persistence/spiegel100.json") + fds, _ := data.NewFileDatastore("persistence/spiegel100.json") if err != nil { http.Error(w, "Failed to read datastore", http.StatusInternalServerError); return; } repo, _ := data.NewDefaultRepository[*model.Article](fds, "article") @@ -62,7 +62,7 @@ func UpSearch(w http.ResponseWriter, req *http.Request) { } // render template - t := template.Must(template.ParseFiles("templates/article.html")) + t := template.Must(template.ParseFiles("web/templates/article.html")) err = t.ExecuteTemplate(w, "content", articleVMs) if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; } } diff --git a/templates/article.html b/web/templates/article.html similarity index 100% rename from templates/article.html rename to web/templates/article.html diff --git a/templates/layout.html b/web/templates/layout.html similarity index 100% rename from templates/layout.html rename to web/templates/layout.html