Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Set up opensearchdescription aka Tab To Search #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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