1
0
mirror of https://github.com/golang/go synced 2024-11-25 01:27:56 -07:00

godoc: added an opensearch description document.

R=golang-dev, r, tux21b, rsc
CC=golang-dev
https://golang.org/cl/5479062
This commit is contained in:
Christoph Hack 2011-12-12 18:01:06 -05:00 committed by Russ Cox
parent fbff033ecf
commit ecf4a9216e
3 changed files with 28 additions and 1 deletions

View File

@ -12,6 +12,9 @@
<link rel="stylesheet" href="/doc/ie.css" type="text/css">
<![endif]-->
<script type="text/javascript" src="/doc/godocs.js"></script>
{{if .SearchBox}}
<link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" />
{{end}}
</head>
<body>
<div id="container">

11
lib/godoc/opensearch.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>godoc</ShortName>
<Description>The Go Programming Language</Description>
<Tags>go golang</Tags>
<Contact />
<Url type="text/html" template="{{.BaseURL}}/search?q={searchTerms}" />
<Image height="15" width="16" type="image/x-icon">/favicon.ico</Image>
<OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding>
</OpenSearchDescription>

View File

@ -105,6 +105,7 @@ func registerPublicHandlers(mux *http.ServeMux) {
mux.HandleFunc("/doc/codewalk/", codewalk)
mux.HandleFunc("/search", search)
mux.Handle("/robots.txt", fileServer)
mux.HandleFunc("/opensearch.xml", serveSearchDesc)
mux.HandleFunc("/", serveFile)
}
@ -600,7 +601,8 @@ var (
packageHTML,
packageText,
searchHTML,
searchText *template.Template
searchText,
searchDescXML *template.Template
)
func readTemplates() {
@ -615,6 +617,7 @@ func readTemplates() {
packageText = readTemplate("package.txt")
searchHTML = readTemplate("search.html")
searchText = readTemplate("search.txt")
searchDescXML = readTemplate("opensearch.xml")
}
// ----------------------------------------------------------------------------
@ -809,6 +812,16 @@ func serveFile(w http.ResponseWriter, r *http.Request) {
fileServer.ServeHTTP(w, r)
}
func serveSearchDesc(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
data := map[string]interface{}{
"BaseURL": fmt.Sprintf("http://%s", r.Host),
}
if err := searchDescXML.Execute(w, &data); err != nil {
log.Printf("searchDescXML.Execute: %s", err)
}
}
// ----------------------------------------------------------------------------
// Packages