Skip to content
Snippets Groups Projects
Commit fc20fe02 authored by ale's avatar ale
Browse files

add opensearch metadata

parent e1483b4e
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head profile="http://a9.com/-/spec/opensearch/1.1/">
<title>LIBER</title> <title>LIBER</title>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="shortcut icon" href="/static/favicon.ico"> <link rel="shortcut icon" href="/static/favicon.ico">
<link rel="stylesheet" href="/static/css/bootstrap.min.css"> <link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/liber.css"> <link rel="stylesheet" href="/static/css/liber.css">
<link rel="search"
type="application/opensearchdescription+xml"
href="/opensearch.xml"
title="Book search">
</head> </head>
<body> <body>
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head profile="http://a9.com/-/spec/opensearch/1.1/">
<title>LIBER</title> <title>LIBER</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="/static/favicon.ico"> <link rel="shortcut icon" href="/static/favicon.ico">
<link rel="stylesheet" href="/static/css/bootstrap.min.css"> <link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/home.css"> <link rel="stylesheet" href="/static/css/home.css">
<link rel="search"
type="application/opensearchdescription+xml"
href="/opensearch.xml"
title="Book search">
</head> </head>
<body> <body>
......
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Book Search</ShortName>
<Description>Search this e-book collection.</Description>
<Tags>epub books</Tags>
<Contact>ale@incal.net</Contact>
<Url type="application/rss+xml"
template="{{.URL}}"/>
<OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding>
</OpenSearchDescription>
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"net/url"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
...@@ -313,6 +314,28 @@ func render(templateName string, w http.ResponseWriter, ctx interface{}) { ...@@ -313,6 +314,28 @@ func render(templateName string, w http.ResponseWriter, ctx interface{}) {
io.Copy(w, &buf) 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 { func NewHttpServer(db *Database, storage, cache *FileStorage, addr string) *http.Server {
var err error var err error
tpl, err = template.New("liber").Funcs(template.FuncMap{ tpl, err = template.New("liber").Funcs(template.FuncMap{
...@@ -335,6 +358,7 @@ func NewHttpServer(db *Database, storage, cache *FileStorage, addr string) *http ...@@ -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("/book/{id:[0-9]+}", uisrv.withBook(uisrv.handleShowBook))
r.Handle("/read/{id:[0-9]+}/{fid:[0-9]+}", uisrv.withFile(uisrv.handleReadBook)) 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.Handle("/dl/{id:[0-9]+}/{fid:[0-9]+}", uisrv.withFile(uisrv.handleDownloadBook))
r.HandleFunc("/opensearch.xml", handleOpenSearchXml)
r.HandleFunc("/suggest", uisrv.handleAutocomplete) r.HandleFunc("/suggest", uisrv.handleAutocomplete)
r.HandleFunc("/search", uisrv.handleSearch) r.HandleFunc("/search", uisrv.handleSearch)
r.HandleFunc("/", uisrv.handleHome) r.HandleFunc("/", uisrv.handleHome)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment