diff --git a/img/feed.png b/img/feed.png new file mode 100644 index 0000000..80ccac8 Binary files /dev/null and b/img/feed.png differ diff --git a/search.go b/search.go index 61e20e7..dbfd040 100644 --- a/search.go +++ b/search.go @@ -62,5 +62,11 @@ func searchHandler(w http.ResponseWriter, r *http.Request, sess *Session) { if page > 0 { data.Prev = "/search/?q=" + req + "&p=" + strconv.Itoa(page-1) } - loadTemplate(w, "search", data) + + format := r.Form["fmt"] + if (len(format) > 0) && (format[0] == "rss") { + loadTxtTemplate(w, "search_rss.xml", data) + } else { + loadTemplate(w, "search", data) + } } diff --git a/template.go b/template.go index b5b6cd7..1a64b0b 100644 --- a/template.go +++ b/template.go @@ -5,7 +5,11 @@ import ( "net/http" ) +import txt_tmpl "text/template" + type Status struct { + BaseURL string + FullURL string Search string User string IsAdmin bool @@ -22,6 +26,8 @@ func GetStatus(w http.ResponseWriter, r *http.Request) Status { var s Status sess := GetSession(r) sess.Save(w, r) + s.BaseURL = "http://" + r.Host + s.FullURL = s.BaseURL + r.RequestURI s.User = sess.User s.IsAdmin = sess.IsAdmin() s.Notif = sess.Notif @@ -53,3 +59,13 @@ func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) { return } } + +var txt_templates = txt_tmpl.Must(txt_tmpl.ParseFiles(TEMPLATE_PATH + "search_rss.xml")) + +func loadTxtTemplate(w http.ResponseWriter, tmpl string, data interface{}) { + err := txt_templates.ExecuteTemplate(w, tmpl, data) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} diff --git a/templates/header.html b/templates/header.html index d1bb60e..67a45d7 100644 --- a/templates/header.html +++ b/templates/header.html @@ -6,6 +6,7 @@ + Imperial Library of Trantor diff --git a/templates/index.html b/templates/index.html index cd0f7a5..9a5ddee 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,7 +8,7 @@
-

Last books added:

+

Last books added:

{{.Count}} books

diff --git a/templates/search.html b/templates/search.html index ec172d8..cb446d6 100644 --- a/templates/search.html +++ b/templates/search.html @@ -1,6 +1,6 @@ {{template "header.html" .S}} -

Found {{.Found}} books. Page {{.Page}}

+

Found {{.Found}} books. Page {{.Page}}