Quellcode durchsuchen

[enh][fix] opensearch separation ++ better chrome support

asciimoo vor 11 Jahren
Ursprung
Commit
941e5fb2c4
2 geänderte Dateien mit 15 neuen und 16 gelöschten Zeilen
  1. 14
    0
      searx/templates/opensearch.xml
  2. 1
    16
      searx/webapp.py

+ 14
- 0
searx/templates/opensearch.xml Datei anzeigen

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
3
+  <ShortName>searx</ShortName>
4
+  <Description>Search searx</Description>
5
+  <InputEncoding>UTF-8</InputEncoding>
6
+  <LongName>searx metasearch</LongName>
7
+  {% if method == 'get' %}
8
+    <Url type="text/html" method="get" template="{{ host }}?q={searchTerms}"/>
9
+  {% else %}
10
+    <Url type="text/html" method="post" template="{{ host }}">
11
+      <Param name="q" value="{searchTerms}" />
12
+    </Url>
13
+  {% endif %}
14
+</OpenSearchDescription>

+ 1
- 16
searx/webapp.py Datei anzeigen

@@ -48,19 +48,6 @@ favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
48 48
             'twitter', 'stackoverflow', 'github']
49 49
 
50 50
 
51
-opensearch_xml = '''<?xml version="1.0" encoding="utf-8"?>
52
-<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
53
-  <ShortName>searx</ShortName>
54
-  <Description>Search searx</Description>
55
-  <InputEncoding>UTF-8</InputEncoding>
56
-  <LongName>searx meta search engine</LongName>
57
-  <Url type="text/html" method="{method}" template="{host}">
58
-    <Param name="q" value="{{searchTerms}}" />
59
-  </Url>
60
-</OpenSearchDescription>
61
-'''
62
-
63
-
64 51
 @babel.localeselector
65 52
 def get_locale():
66 53
     locale = request.accept_languages.best_match(settings['locales'].keys())
@@ -298,13 +285,11 @@ Disallow: /engines
298 285
 
299 286
 @app.route('/opensearch.xml', methods=['GET'])
300 287
 def opensearch():
301
-    global opensearch_xml
302 288
     method = 'post'
303 289
     # chrome/chromium only supports HTTP GET....
304 290
     if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
305 291
         method = 'get'
306
-    base_url = get_base_url()
307
-    ret = opensearch_xml.format(method=method, host=base_url)
292
+    ret = render('opensearch.xml', method=method, host=get_base_url())
308 293
     resp = Response(response=ret,
309 294
                     status=200,
310 295
                     mimetype="application/xml")