diff --git a/book.html b/book.html index 35aa8eb..fe53ba1 100644 --- a/book.html +++ b/book.html @@ -1,3 +1,5 @@ +{{template "header.html"}} +

{{.Title}}

{{.Description}}

{{.Title}} @@ -10,3 +12,5 @@

download

+ +{{template "footer.html"}} diff --git a/foot.html b/footer.html similarity index 100% rename from foot.html rename to footer.html diff --git a/head.html b/header.html similarity index 100% rename from head.html rename to header.html diff --git a/front.html b/index.html similarity index 80% rename from front.html rename to index.html index 5cb972e..e4a9e52 100644 --- a/front.html +++ b/index.html @@ -1,3 +1,5 @@ +{{template "header.html"}} +

Imperial Library of Trantor

@@ -5,3 +7,5 @@

Search on {{.}} books.

library

+ +{{template "footer.html"}} diff --git a/search.html b/search.html index bc2631f..57e26d3 100644 --- a/search.html +++ b/search.html @@ -1,3 +1,5 @@ +{{template "header.html"}} +

Search

@@ -17,3 +19,5 @@

{{if .Prev}}<Prev {{end}} {{if .Next}}Next>{{end}}

+ +{{template "footer.html"}} diff --git a/template.go b/template.go index 2c3dd68..7ebd0e3 100644 --- a/template.go +++ b/template.go @@ -7,20 +7,9 @@ import ( func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) { // TODO: when finish devel conver to global: - var templates = template.Must(template.ParseFiles("head.html", "foot.html", "front.html", "book.html", "search.html", "upload.html")) + var templates = template.Must(template.ParseFiles("header.html", "footer.html", "index.html", "book.html", "search.html", "upload.html")) - // TODO: use includes - err := templates.ExecuteTemplate(w, "head.html", nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - err = templates.ExecuteTemplate(w, tmpl+".html", data) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - err = templates.ExecuteTemplate(w, "foot.html", nil) + err := templates.ExecuteTemplate(w, tmpl+".html", data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/trantor.go b/trantor.go index 9e5a950..804382c 100644 --- a/trantor.go +++ b/trantor.go @@ -39,6 +39,6 @@ func main() { fileHandler("/img/") fileHandler("/cover/") fileHandler("/books/") - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { loadTemplate(w, "front", num) }) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { loadTemplate(w, "index", num) }) http.ListenAndServe(":8080", nil) } diff --git a/upload.html b/upload.html index 04edb61..469deb5 100644 --- a/upload.html +++ b/upload.html @@ -1,4 +1,8 @@ +{{template "header.html"}} +
+ +{{template "footer.html"}}