finale Anpassung
This commit is contained in:
@@ -46,19 +46,22 @@ func main() {
|
||||
}
|
||||
|
||||
// Basislayout zuerst parsen
|
||||
base := template.Must(
|
||||
layout := template.Must(
|
||||
template.New("base").Funcs(funcs).
|
||||
ParseFiles("internal/web/templates/base.html"),
|
||||
)
|
||||
|
||||
// LIST‑Seite: base + list.html
|
||||
tplList = template.Must(base.Clone())
|
||||
tplList = template.Must(layout.Clone())
|
||||
template.Must(tplList.Funcs(funcs).ParseFiles("internal/web/templates/list.html"))
|
||||
|
||||
// ARTICLE‑Instanz
|
||||
tplArticle = template.Must(base.Clone())
|
||||
tplArticle = template.Must(layout.Clone())
|
||||
template.Must(tplArticle.Funcs(funcs).ParseFiles("internal/web/templates/article.html"))
|
||||
|
||||
tplPage := template.Must(layout.Clone())
|
||||
template.Must(tplPage.ParseFiles("internal/web/templates/page.html"))
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
staticDir := "internal/web/static"
|
||||
@@ -68,6 +71,13 @@ func main() {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
staticPages, err := article.LoadStatic("pages")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(staticPages)
|
||||
}
|
||||
|
||||
// Handler für /
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
@@ -92,6 +102,19 @@ func main() {
|
||||
http.NotFound(w, r)
|
||||
})
|
||||
|
||||
mux.HandleFunc("/page/", func(w http.ResponseWriter, r *http.Request) {
|
||||
slug := strings.TrimPrefix(r.URL.Path, "/page/")
|
||||
p, ok := staticPages[slug]
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
// "layout" kommt aus deinem Template‑Pool (list/article nutzen es ja auch)
|
||||
if err := tplPage.ExecuteTemplate(w, "page", p); err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
}
|
||||
})
|
||||
|
||||
mux.Handle("/static/",
|
||||
cacheControl(http.StripPrefix("/static/",
|
||||
http.FileServer(http.Dir(staticDir)))))
|
||||
|
Reference in New Issue
Block a user