瀏覽代碼

Merge branch 'Cqoicebordel-Detect-favicons'

Adam Tauber 10 年之前
父節點
當前提交
b4f39237a3

+ 2
- 2
searx/templates/courgette/result_templates/default.html 查看文件

@@ -1,7 +1,7 @@
1 1
 <div class="result {{ result.class }}">
2 2
 
3
-  {% if result['favicon'] %}
4
-    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />
3
+  {% if "icon_"~result.engine~".ico" in favicons %}
4
+    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />
5 5
   {% endif %}
6 6
 
7 7
   <div>

+ 2
- 2
searx/templates/courgette/result_templates/map.html 查看文件

@@ -1,7 +1,7 @@
1 1
 <div class="result {{ result.class }}">
2 2
 
3
-  {% if result['favicon'] %}
4
-    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />
3
+  {% if "icon_"~result.engine~".ico" in favicons %}
4
+    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />
5 5
   {% endif %}
6 6
 
7 7
   <div>

+ 2
- 2
searx/templates/courgette/result_templates/videos.html 查看文件

@@ -1,6 +1,6 @@
1 1
 <div class="result">
2
-  {% if result['favicon'] %}
3
-    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />
2
+  {% if "icon_"~result.engine~".ico" in favicons %}
3
+    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />
4 4
   {% endif %}
5 5
 
6 6
       <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>

+ 1
- 1
searx/templates/default/result_templates/default.html 查看文件

@@ -1,5 +1,5 @@
1 1
 <div class="result {{ result.class }}">
2
-    <h3 class="result_title"> {% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
2
+    <h3 class="result_title">{% if "icon_"~result.engine~".ico" in favicons %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
3 3
     <p class="url">{{ result.pretty_url }} <a class="cache_link" href="https://web.archive.org/web/{{ result.url }}">cached</a></p>
4 4
     {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
5 5
     <p class="content">{% if result.img_src %}<img src="{{ result.img_src }}" class="image" />{% endif %}{% if result.content %}{{ result.content|safe }}<br class="last"/>{% endif %}</p>

+ 2
- 2
searx/templates/default/result_templates/map.html 查看文件

@@ -1,7 +1,7 @@
1 1
 <div class="result {{ result.class }}">
2 2
 
3
-  {% if result['favicon'] %}
4
-    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />
3
+  {% if "icon_"~result.engine~".ico" in favicons %}
4
+    <img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />
5 5
   {% endif %}
6 6
 
7 7
   <div>

+ 1
- 1
searx/templates/default/result_templates/videos.html 查看文件

@@ -1,5 +1,5 @@
1 1
 <div class="result">
2
-      <h3 class="result_title"> {% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
2
+      <h3 class="result_title">{% if "icon_"~result.engine~".ico" in favicons %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result.engine}}.ico" alt="{{result.engine}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
3 3
       {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
4 4
       <a href="{{ result.url }}"><img class="thumbnail" src="{{ result.thumbnail }}" title="{{ result.title|striptags }}" alt="{{ result.title|striptags }}"/></a>
5 5
       <p class="url">{{ result.url }}</p>

+ 1
- 1
searx/templates/oscar/result_templates/default.html 查看文件

@@ -1,6 +1,6 @@
1 1
 {% from 'oscar/macros.html' import icon %}
2 2
 
3
-<h4 class="result_header">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
3
+<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
4 4
 
5 5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6 6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>

+ 1
- 1
searx/templates/oscar/result_templates/images.html 查看文件

@@ -7,7 +7,7 @@
7 7
         <div class="modal-content">
8 8
             <div class="modal-header">
9 9
                 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
10
-                <h4 class="modal-title">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}{{ result.title|striptags }}</h4>
10
+                <h4 class="modal-title">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}{{ result.title|striptags }}</h4>
11 11
             </div>
12 12
             <div class="modal-body">
13 13
                 <img class="img-responsive center-block" src="{{ result.img_src }}" alt="{{ result.title }}">

+ 1
- 1
searx/templates/oscar/result_templates/map.html 查看文件

@@ -1,6 +1,6 @@
1 1
 {% from 'oscar/macros.html' import icon %}
2 2
 
3
-<h4 class="result_header">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
3
+<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
4 4
 
5 5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6 6
 

+ 1
- 1
searx/templates/oscar/result_templates/torrent.html 查看文件

@@ -1,6 +1,6 @@
1 1
 {% from 'oscar/macros.html' import icon %}
2 2
 
3
-<h4 class="result_header">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
3
+<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
4 4
 
5 5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6 6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>

+ 2
- 2
searx/templates/oscar/result_templates/videos.html 查看文件

@@ -1,13 +1,13 @@
1 1
 {% from 'oscar/macros.html' import icon %}
2 2
 
3
-<h4 class="result_header">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
3
+<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
4 4
     
5 5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6 6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
7 7
 
8 8
 <div class="container-fluid">
9 9
     <div class="row">
10
-        <img class="thumbnail col-xs-6 col-sm-4 col-md-4 result-content" src="{{ result.thumbnail|safe }}" alt="{{ result.title|urlencode }} {{ result['favicon'] }}" />
10
+        <a href="{{ result.url }}"><img class="thumbnail col-xs-6 col-sm-4 col-md-4 result-content" src="{{ result.thumbnail|safe }}" alt="{{ result.title|striptags }} {{ result.engine }}" /></a>
11 11
         {% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8 result-content">{{ result.content|safe }}</p>{% endif %}
12 12
     </div>
13 13
 </div>

+ 8
- 8
searx/webapp.py 查看文件

@@ -65,9 +65,12 @@ app.secret_key = settings['server']['secret_key']
65 65
 
66 66
 babel = Babel(app)
67 67
 
68
-#TODO configurable via settings.yml
69
-favicons = ['wikipedia', 'youtube', 'vimeo', 'dailymotion', 'soundcloud',
70
-            'twitter', 'stackoverflow', 'github', 'deviantart', 'kickass']
68
+global_favicons = []
69
+for indice, theme in enumerate(themes):
70
+    global_favicons.append([])
71
+    theme_img_path = searx_dir+"/static/"+theme+"/img/"
72
+    for (dirpath, dirnames, filenames) in os.walk(theme_img_path):
73
+        global_favicons[indice].extend(filenames)
71 74
 
72 75
 cookie_max_age = 60 * 60 * 24 * 365 * 23  # 23 years
73 76
 
@@ -233,10 +236,6 @@ def index():
233 236
         else:
234 237
             result['pretty_url'] = result['url']
235 238
 
236
-        for engine in result['engines']:
237
-            if engine in favicons:
238
-                result['favicon'] = engine
239
-
240 239
         # TODO, check if timezone is calculated right
241 240
         if 'publishedDate' in result:
242 241
             result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')
@@ -289,7 +288,8 @@ def index():
289 288
         suggestions=search.suggestions,
290 289
         answers=search.answers,
291 290
         infoboxes=search.infoboxes,
292
-        theme=get_current_theme_name()
291
+        theme=get_current_theme_name(),
292
+        favicons=global_favicons[themes.index(get_current_theme_name())]
293 293
     )
294 294
 
295 295