Skip to content

Commit 711a91d

Browse files
committed
frontend: Set up opensearchdescription aka Tab To Search
This used to work on godoc.org, let's set it up for pkg.go.dev too. golang/go#58133
1 parent 035bfc0 commit 711a91d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/frontend/server.go

+16
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Disallow: /fetch/*
193193
Sitemap: https://pkg.go.dev/sitemap/index.xml
194194
`))
195195
}))
196+
handle("/opensearch.xml", s.opensearchHandler())
196197
s.installDebugHandlers(handle)
197198
}
198199

@@ -466,6 +467,21 @@ func (s *Server) aboutHandler() http.HandlerFunc {
466467
})
467468
}
468469

470+
func (s *Server) opensearchHandler() http.HandlerFunc {
471+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
472+
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
473+
http.ServeContent(w, r, "", time.Time{}, strings.NewReader(`<?xml version="1.0"?>
474+
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
475+
<InputEncoding>UTF-8</InputEncoding>
476+
<ShortName>Go Packages</ShortName>
477+
<Description>Go Packages: Go Package Documentation</Description>
478+
<Url type="text/html" method="get" template="https://` + r.Host + `/search?q={searchTerms}"/>
479+
<Url type="application/opensearchdescription+xml" rel="self" template="https://` + r.Host + `/opensearch.xml"/>
480+
</OpenSearchDescription>
481+
`))
482+
})
483+
}
484+
469485
// newBasePage returns a base page for the given request and title.
470486
func (s *Server) newBasePage(r *http.Request, title string) basePage {
471487
q := rawSearchQuery(r)

static/frontend/frontend.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<link rel="shortcut icon" href="/static/shared/icon/favicon.ico">
3131
{{block "canonical" .}}{{end}}
3232
<link href="/static/frontend/frontend.min.css?version={{.AppVersionLabel}}" rel="stylesheet">
33+
<link type="application/opensearchdescription+xml" rel="search" href="/opensearch.xml?version={{.AppVersionLabel}}" title="Go Packages" />
3334
{{block "title" .}}
3435
<title>Go Packages</title>
3536
{{end}}

0 commit comments

Comments
 (0)