move templates to web dir

This commit is contained in:
2025-01-02 15:13:13 +01:00
parent 59222160af
commit 7798930145
5 changed files with 5 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ func main() {
http.HandleFunc("POST /up/search", routes.UpSearch) http.HandleFunc("POST /up/search", routes.UpSearch)
// serve files from the "static" directory // 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)) http.Handle("GET /static/", http.StripPrefix("/", fs))
// start server // start server

View File

@@ -17,7 +17,7 @@ func (ord articleDateOrder) Weight(a *model.Article) int {
// List the latest articles using the base template. // List the latest articles using the base template.
func Index(w http.ResponseWriter, req *http.Request) { func Index(w http.ResponseWriter, req *http.Request) {
// retrieve from repo // 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; } if err != nil { http.Error(w, "Failed to load datastore", http.StatusInternalServerError); return; }
repo, err := data.NewDefaultRepository[*model.Article](fds, "article") repo, err := data.NewDefaultRepository[*model.Article](fds, "article")
if err != nil { http.Error(w, "Failed to create repository", http.StatusInternalServerError); return; } 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 // 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) err = t.ExecuteTemplate(w, "base", articleVMs)
if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; } if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; }
} }

View File

@@ -40,7 +40,7 @@ func UpSearch(w http.ResponseWriter, req *http.Request) {
} }
// retrieve from repo // 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; } if err != nil { http.Error(w, "Failed to read datastore", http.StatusInternalServerError); return; }
repo, _ := data.NewDefaultRepository[*model.Article](fds, "article") repo, _ := data.NewDefaultRepository[*model.Article](fds, "article")
@@ -62,7 +62,7 @@ func UpSearch(w http.ResponseWriter, req *http.Request) {
} }
// render template // 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) err = t.ExecuteTemplate(w, "content", articleVMs)
if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; } if err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError); return; }
} }