Restructure templates to use includes
This commit is contained in:
parent
8e4a37b558
commit
18454021c3
8 changed files with 19 additions and 14 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
{{template "header.html"}}
|
||||||
|
|
||||||
<h1>{{.Title}}</h1>
|
<h1>{{.Title}}</h1>
|
||||||
<p>{{.Description}}</p>
|
<p>{{.Description}}</p>
|
||||||
<img src="{{.Cover}}" alt="{{.Title}}" />
|
<img src="{{.Cover}}" alt="{{.Title}}" />
|
||||||
|
@ -10,3 +12,5 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p><a href="/{{.Path}}">download</a></p>
|
<p><a href="/{{.Path}}">download</a></p>
|
||||||
|
|
||||||
|
{{template "footer.html"}}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{{template "header.html"}}
|
||||||
|
|
||||||
<h1>Imperial Library of Trantor</h1>
|
<h1>Imperial Library of Trantor</h1>
|
||||||
<form action="/search/">
|
<form action="/search/">
|
||||||
<input type="search" name="q" />
|
<input type="search" name="q" />
|
||||||
|
@ -5,3 +7,5 @@
|
||||||
</form>
|
</form>
|
||||||
<p>Search on {{.}} books.</p>
|
<p>Search on {{.}} books.</p>
|
||||||
<p><img src="/img/library.jpg" alt="library" /></p>
|
<p><img src="/img/library.jpg" alt="library" /></p>
|
||||||
|
|
||||||
|
{{template "footer.html"}}
|
|
@ -1,3 +1,5 @@
|
||||||
|
{{template "header.html"}}
|
||||||
|
|
||||||
<h1>Search</h1>
|
<h1>Search</h1>
|
||||||
<form action="/search/">
|
<form action="/search/">
|
||||||
<input type="search" name="q" value="{{.Search}}"/>
|
<input type="search" name="q" value="{{.Search}}"/>
|
||||||
|
@ -17,3 +19,5 @@
|
||||||
<p>
|
<p>
|
||||||
{{if .Prev}}<a href="{{.Prev}}"><Prev</a> {{end}}
|
{{if .Prev}}<a href="{{.Prev}}"><Prev</a> {{end}}
|
||||||
{{if .Next}}<a href="{{.Next}}">Next></a>{{end}}</p>
|
{{if .Next}}<a href="{{.Next}}">Next></a>{{end}}</p>
|
||||||
|
|
||||||
|
{{template "footer.html"}}
|
||||||
|
|
15
template.go
15
template.go
|
@ -7,20 +7,9 @@ import (
|
||||||
|
|
||||||
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
||||||
// TODO: when finish devel conver to global:
|
// 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, tmpl+".html", data)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
@ -39,6 +39,6 @@ func main() {
|
||||||
fileHandler("/img/")
|
fileHandler("/img/")
|
||||||
fileHandler("/cover/")
|
fileHandler("/cover/")
|
||||||
fileHandler("/books/")
|
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)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
|
{{template "header.html"}}
|
||||||
|
|
||||||
<form method="POST" enctype="multipart/form-data">
|
<form method="POST" enctype="multipart/form-data">
|
||||||
<input accept="application/epub+zip" type="file" name="epub" />
|
<input accept="application/epub+zip" type="file" name="epub" />
|
||||||
<input type="submit" />
|
<input type="submit" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{{template "footer.html"}}
|
||||||
|
|
Reference in a new issue