npm / www

community space for the npm website
https://npm.community
69 stars 48 forks source link

Feature: Add OpenSearch support to the package search #429

Open cristianl opened 6 years ago

cristianl commented 6 years ago

This allows browsers to automatically add search engines from visited websites.

Why

Some browsers, such as Safari, only support custom search engines from websites that implement OpenSearch.

In some browsers, the user experience of adding a custom search engine is improved for websites supporting OpenSearch: the user does not have to figure out the pattern of search URLs for that website, and there's no need for some third-party browser extension or search engine definition.

Implementation

This requires a link tag in the head element, and a XML file describing the search URL format.

In GitHub, the element is:

<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub">

And the XML file:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>GitHub</ShortName>
  <Description>Search GitHub</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">https://github.com/favicon.ico</Image>
  <Url type="text/html" method="get" template="https://github.com/search?q={searchTerms}&amp;ref=opensearch"/>
  <moz:SearchForm>https://github.com/search</moz:SearchForm>
</OpenSearchDescription>