diff --git a/htdocs/templates/_head.html b/htdocs/templates/_head.html index 38c2c6009aaba5ec812ba549f132a6b70807a748..b19913e596d756cfa7c7a79a414e4a6e723a0aaa 100644 --- a/htdocs/templates/_head.html +++ b/htdocs/templates/_head.html @@ -1,11 +1,15 @@ - + LIBER + diff --git a/htdocs/templates/index.html b/htdocs/templates/index.html index 58bd03021786a07c6114ed64cb31f0faa376f1e0..9cc4756b3af2b7744aa90631344493221850f6d9 100644 --- a/htdocs/templates/index.html +++ b/htdocs/templates/index.html @@ -1,11 +1,15 @@ - + LIBER - + + diff --git a/htdocs/templates/opensearch_xml.html b/htdocs/templates/opensearch_xml.html new file mode 100644 index 0000000000000000000000000000000000000000..59c35639e85fa1923d808293e18716a672df0686 --- /dev/null +++ b/htdocs/templates/opensearch_xml.html @@ -0,0 +1,11 @@ + + + Book Search + Search this e-book collection. + epub books + ale@incal.net + + UTF-8 + UTF-8 + diff --git a/web.go b/web.go index c2e18d674553fb5931107c98eb28eaf5d1a26404..2335689cae4aebc95823d84fe1a27df050e37de0 100644 --- a/web.go +++ b/web.go @@ -9,6 +9,7 @@ import ( "io" "log" "net/http" + "net/url" "os/exec" "path/filepath" "strconv" @@ -313,6 +314,28 @@ func render(templateName string, w http.ResponseWriter, ctx interface{}) { io.Copy(w, &buf) } +func fullURL(req *http.Request) *url.URL { + u := *req.URL + u.Host = req.Host + if req.TLS != nil || req.Header.Get("X-Forwarded-Proto") == "https" { + u.Scheme = "https" + } else { + u.Scheme = "http" + } + return &u +} + +func handleOpenSearchXml(w http.ResponseWriter, req *http.Request) { + searchURL := fullURL(req) + searchURL.Path = "/search" + searchURL.RawQuery = "q={searchTerms}&pw={startPage}" + ctx := struct { + URL string + }{searchURL.String()} + w.Header().Set("Content-Type", "application/opensearchdescription+xml") + render("opensearch_xml.html", w, &ctx) +} + func NewHttpServer(db *Database, storage, cache *FileStorage, addr string) *http.Server { var err error tpl, err = template.New("liber").Funcs(template.FuncMap{ @@ -335,6 +358,7 @@ func NewHttpServer(db *Database, storage, cache *FileStorage, addr string) *http r.Handle("/book/{id:[0-9]+}", uisrv.withBook(uisrv.handleShowBook)) r.Handle("/read/{id:[0-9]+}/{fid:[0-9]+}", uisrv.withFile(uisrv.handleReadBook)) r.Handle("/dl/{id:[0-9]+}/{fid:[0-9]+}", uisrv.withFile(uisrv.handleDownloadBook)) + r.HandleFunc("/opensearch.xml", handleOpenSearchXml) r.HandleFunc("/suggest", uisrv.handleAutocomplete) r.HandleFunc("/search", uisrv.handleSearch) r.HandleFunc("/", uisrv.handleHome)