Skip to content

Commit

Permalink
frontend: Set up opensearchdescription aka Tab To Search
Browse files Browse the repository at this point in the history
This used to work on godoc.org, let's set it up for pkg.go.dev too.

golang/go#58133
  • Loading branch information
Jille committed Jan 29, 2023
1 parent 035bfc0 commit 711a91d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/frontend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Disallow: /fetch/*
Sitemap: https://pkg.go.dev/sitemap/index.xml
`))
}))
handle("/opensearch.xml", s.opensearchHandler())
s.installDebugHandlers(handle)
}

Expand Down Expand Up @@ -466,6 +467,21 @@ func (s *Server) aboutHandler() http.HandlerFunc {
})
}

func (s *Server) opensearchHandler() http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
http.ServeContent(w, r, "", time.Time{}, strings.NewReader(`<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<InputEncoding>UTF-8</InputEncoding>
<ShortName>Go Packages</ShortName>
<Description>Go Packages: Go Package Documentation</Description>
<Url type="text/html" method="get" template="https://` + r.Host + `/search?q={searchTerms}"/>
<Url type="application/opensearchdescription+xml" rel="self" template="https://` + r.Host + `/opensearch.xml"/>
</OpenSearchDescription>
`))
})
}

// newBasePage returns a base page for the given request and title.
func (s *Server) newBasePage(r *http.Request, title string) basePage {
q := rawSearchQuery(r)
Expand Down
1 change: 1 addition & 0 deletions static/frontend/frontend.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<link rel="shortcut icon" href="/static/shared/icon/favicon.ico">
{{block "canonical" .}}{{end}}
<link href="/static/frontend/frontend.min.css?version={{.AppVersionLabel}}" rel="stylesheet">
<link type="application/opensearchdescription+xml" rel="search" href="/opensearch.xml?version={{.AppVersionLabel}}" title="Go Packages" />
{{block "title" .}}
<title>Go Packages</title>
{{end}}
Expand Down

0 comments on commit 711a91d

Please sign in to comment.