diff --git a/config.go b/config.go index 14be217..2fd74f7 100644 --- a/config.go +++ b/config.go @@ -34,6 +34,7 @@ const ( IMG_PATH = "img/" ROBOTS_PATH = "robots.txt" DESCRIPTION_PATH = "description.json" + OPENSEARCH_PATH = "opensearch.xml" LOGGER_CONFIG = "logger.xml" IMG_WIDTH_BIG = 300 diff --git a/opensearch.xml b/opensearch.xml new file mode 100644 index 0000000..6f6dd60 --- /dev/null +++ b/opensearch.xml @@ -0,0 +1,11 @@ + + + Imperial Library of Trantor + Book search in the library. + UTF-8 + UTF-8 + books epub + /img/favicon.ico + zenow@riseup.net + + diff --git a/template.go b/template.go index 4e9225c..69a600f 100644 --- a/template.go +++ b/template.go @@ -9,6 +9,7 @@ import ( "errors" "html/template" "net/http" + "time" "git.gitorious.org/trantor/trantor.git/database" ) @@ -20,6 +21,7 @@ type Status struct { User string IsAdmin bool Notif []Notification + Updated string Home bool About bool News bool @@ -36,6 +38,7 @@ func GetStatus(h handler) Status { s.User = h.sess.User s.IsAdmin = h.sess.IsAdmin() s.Notif = h.sess.GetNotif() + s.Updated = time.Now().UTC().Format("2006-01-02T15:04:05Z") h.sess.Save(h.w, h.r) return s } @@ -66,12 +69,19 @@ var tmpl_rss = txt_tmpl.Must(txt_tmpl.ParseFiles( TEMPLATE_PATH+"news.rss", )) +var tmpl_opds = txt_tmpl.Must(txt_tmpl.ParseFiles( + TEMPLATE_PATH+"index.opds", + TEMPLATE_PATH+"search.opds", +)) + func loadTemplate(h handler, tmpl string, data interface{}) { var err error fmt := h.r.FormValue("fmt") switch fmt { case "rss": err = tmpl_rss.ExecuteTemplate(h.w, tmpl+".rss", data) + case "opds": + err = tmpl_opds.ExecuteTemplate(h.w, tmpl+".opds", data) case "json": err = loadJson(h.w, tmpl, data) default: diff --git a/templates/index.opds b/templates/index.opds new file mode 100644 index 0000000..85c57cb --- /dev/null +++ b/templates/index.opds @@ -0,0 +1,52 @@ + + + {{.S.BaseURL}} + + + + + The Imperial Libary of Trantor + + The Imperial Library of Trantor + {{.S.BaseURL}} + zenow@riseup.net + + {{.S.Updated}} + {{.S.BaseURL}}/img/favicon.ico + + + Last books added + + {{.S.Updated}} + {{.S.BaseURL}}/search/ + +{{$updated := .S.Updated}} +{{$baseurl := .S.BaseURL}} +{{range .Tags}} + + {{html .}} + + {{$updated}} + {{$baseurl}}/search/?subject:{{urlquery .}} + +{{end}} + diff --git a/templates/search.opds b/templates/search.opds new file mode 100644 index 0000000..4c00ef6 --- /dev/null +++ b/templates/search.opds @@ -0,0 +1,100 @@ + + + {{.S.BaseURL}}/search/?q={{.S.Search}} + {{.S.BaseURL}}/img/favicon.ico + + + + + {{if .Prev}} + + + {{end}} + {{if .Next}} + + {{end}} + + + + {{.Found}} + {{.ItemsPage}} + + search {{.S.Search}} + + The Imperial Library of Trantor + {{.S.BaseURL}} + zenow@riseup.net + + {{.S.Updated}} + + +{{$updated := .S.Updated}} +{{$baseurl := .S.BaseURL}} +{{range .Books}} + + {{html .Title}} + {{$baseurl}}/book/{{.Id}} + {{$updated}} + + {{range .Author}} + + {{html .}} + + {{end}} + {{if .Contributor}} + + {{html .Contributor}} + + {{end}} + + {{if .Isbn}} + urn:isbn:{{.Isbn}} + {{end}} + {{html .Publisher}} + {{if .Date}} + {{.Date}} + {{end}} + + {{range .Lang}} + {{.}} + {{end}} + {{range .Subject}} + + {{end}} + {{html .Description}} + + + + + + +{{end}} + diff --git a/trantor.go b/trantor.go index ed16ab7..36b9fce 100644 --- a/trantor.go +++ b/trantor.go @@ -187,6 +187,7 @@ func initRouter(db *database.DB, sg *StatsGatherer) { r.HandleFunc("/", sg.Gather(indexHandler)) r.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, ROBOTS_PATH) }) r.HandleFunc("/description.json", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, DESCRIPTION_PATH) }) + r.HandleFunc("/opensearch.xml", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, OPENSEARCH_PATH) }) r.HandleFunc("/book/{id:"+id_pattern+"}", sg.Gather(bookHandler)) r.HandleFunc("/search/", sg.Gather(searchHandler))