mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 20:17:45 +01:00
Merge pull request #1655 from return42/fix-opensearch
[fix] improve OpenSearch description
This commit is contained in:
commit
0043190643
@ -1,22 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||||
<ShortName>{{ instance_name }}</ShortName>
|
<ShortName>{{ instance_name }}</ShortName>
|
||||||
<Description>a privacy-respecting, hackable metasearch engine</Description>
|
<LongName>SearXNG metasearch</LongName>
|
||||||
|
<Description>SearXNG is a metasearch engine that respects your privacy.</Description>
|
||||||
<InputEncoding>UTF-8</InputEncoding>
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
<Image>{{ url_for('static', filename='img/favicon.png', _external=True) }}</Image>
|
<Image type="image/png">{{ url_for('static', filename='img/favicon.png', _external=True) }}</Image>
|
||||||
<LongName>searx metasearch</LongName>
|
{% if opensearch_method == 'GET' %}
|
||||||
{% if opensearch_method == 'get' %}
|
<Url rel="results" type="text/html" method="{{ opensearch_method }}" template="{{ url_for('search', _external=True) }}?q={searchTerms}"/>
|
||||||
<Url rel="results" type="text/html" method="get" template="{{ url_for('search', _external=True) }}?q={searchTerms}"/>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<Url rel="results" type="text/html" method="post" template="{{ url_for('search', _external=True) }}">
|
<Url rel="results" type="text/html" method="{{ opensearch_method }}" template="{{ url_for('search', _external=True) }}">
|
||||||
<Param name="q" value="{searchTerms}" />
|
<Param name="q" value="{searchTerms}" />
|
||||||
</Url>
|
</Url>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if autocomplete %}
|
{% if autocomplete %}
|
||||||
<Url rel="suggestions" type="application/x-suggestions+json" template="{{ url_for('autocompleter', _external=True) }}?q={searchTerms}"/>
|
<Url rel="suggestions" type="application/x-suggestions+json" method="{{ opensearch_method }}" template="{{ url_for('autocompleter', _external=True) }}?q={searchTerms}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<Url rel="self" type="application/opensearchdescription+xml" method="{{ opensearch_method }}" template="{{ opensearch_url }}" />
|
||||||
<Url type="application/opensearchdescription+xml"
|
<Query role="example" searchTerms="SearXNG" />
|
||||||
rel="self"
|
<moz:SearchForm>{{ url_for('search', _external=True) }}</moz:SearchForm>
|
||||||
template="{{ opensearch_url }}" />
|
|
||||||
</OpenSearchDescription>
|
</OpenSearchDescription>
|
||||||
|
@ -1282,19 +1282,17 @@ Disallow: /*?*q=*
|
|||||||
|
|
||||||
@app.route('/opensearch.xml', methods=['GET'])
|
@app.route('/opensearch.xml', methods=['GET'])
|
||||||
def opensearch():
|
def opensearch():
|
||||||
method = 'post'
|
method = request.preferences.get_value('method')
|
||||||
|
autocomplete = request.preferences.get_value('autocomplete')
|
||||||
if request.preferences.get_value('method') == 'GET':
|
|
||||||
method = 'get'
|
|
||||||
|
|
||||||
# chrome/chromium only supports HTTP GET....
|
# chrome/chromium only supports HTTP GET....
|
||||||
if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
|
if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
|
||||||
method = 'get'
|
method = 'GET'
|
||||||
|
|
||||||
autocomplete = request.preferences.get_value('autocomplete')
|
if method not in ('POST', 'GET'):
|
||||||
|
method = 'POST'
|
||||||
|
|
||||||
ret = render('opensearch.xml', opensearch_method=method, autocomplete=autocomplete)
|
ret = render('opensearch.xml', opensearch_method=method, autocomplete=autocomplete)
|
||||||
|
|
||||||
resp = Response(response=ret, status=200, mimetype="application/opensearchdescription+xml")
|
resp = Response(response=ret, status=200, mimetype="application/opensearchdescription+xml")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
@ -244,7 +244,9 @@ class ViewsTestCase(SearxTestCase):
|
|||||||
def test_opensearch_xml(self):
|
def test_opensearch_xml(self):
|
||||||
result = self.app.get('/opensearch.xml')
|
result = self.app.get('/opensearch.xml')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assertIn(b'<Description>a privacy-respecting, hackable metasearch engine</Description>', result.data)
|
self.assertIn(
|
||||||
|
b'<Description>SearXNG is a metasearch engine that respects your privacy.</Description>', result.data
|
||||||
|
)
|
||||||
|
|
||||||
def test_favicon(self):
|
def test_favicon(self):
|
||||||
result = self.app.get('/favicon.ico')
|
result = self.app.get('/favicon.ico')
|
||||||
|
Loading…
Reference in New Issue
Block a user