Browse Source

Merge branch 'Detect-favicons' of https://github.com/Cqoicebordel/searx into Cqoicebordel-Detect-favicons

Conflicts:
	searx/templates/courgette/result_templates/default.html
	searx/templates/courgette/result_templates/map.html
	searx/templates/courgette/result_templates/videos.html
	searx/templates/default/result_templates/default.html
	searx/templates/default/result_templates/map.html
	searx/templates/default/result_templates/videos.html
	searx/webapp.py
Adam Tauber 10 years ago
parent
commit
ada01cb367

+ 2
- 2
searx/templates/courgette/result_templates/default.html View File

1
 <div class="result {{ result.class }}">
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
   {% endif %}
5
   {% endif %}
6
 
6
 
7
   <div>
7
   <div>

+ 2
- 2
searx/templates/courgette/result_templates/map.html View File

1
 <div class="result {{ result.class }}">
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
   {% endif %}
5
   {% endif %}
6
 
6
 
7
   <div>
7
   <div>

+ 2
- 2
searx/templates/courgette/result_templates/videos.html View File

1
 <div class="result">
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
   {% endif %}
4
   {% endif %}
5
 
5
 
6
       <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
6
       <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>

+ 1
- 1
searx/templates/default/result_templates/default.html View File

1
 <div class="result {{ result.class }}">
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
     <p class="url">{{ result.pretty_url }} <a class="cache_link" href="https://web.archive.org/web/{{ result.url }}">cached</a></p>
3
     <p class="url">{{ result.pretty_url }} <a class="cache_link" href="https://web.archive.org/web/{{ result.url }}">cached</a></p>
4
     {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
4
     {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
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>
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 View File

1
 <div class="result {{ result.class }}">
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
   {% endif %}
5
   {% endif %}
6
 
6
 
7
   <div>
7
   <div>

+ 1
- 1
searx/templates/default/result_templates/videos.html View File

1
 <div class="result">
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
       {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
3
       {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
4
       <a href="{{ result.url }}"><img class="thumbnail" src="{{ result.thumbnail }}" title="{{ result.title|striptags }}" alt="{{ result.title|striptags }}"/></a>
4
       <a href="{{ result.url }}"><img class="thumbnail" src="{{ result.thumbnail }}" title="{{ result.title|striptags }}" alt="{{ result.title|striptags }}"/></a>
5
       <p class="url">{{ result.url }}</p>
5
       <p class="url">{{ result.url }}</p>

+ 1
- 1
searx/templates/oscar/result_templates/default.html View File

1
 {% from 'oscar/macros.html' import icon %}
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
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
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 View File

7
         <div class="modal-content">
7
         <div class="modal-content">
8
             <div class="modal-header">
8
             <div class="modal-header">
9
                 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
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
             </div>
11
             </div>
12
             <div class="modal-body">
12
             <div class="modal-body">
13
                 <img class="img-responsive center-block" src="{{ result.img_src }}" alt="{{ result.title }}">
13
                 <img class="img-responsive center-block" src="{{ result.img_src }}" alt="{{ result.title }}">

+ 1
- 1
searx/templates/oscar/result_templates/map.html View File

1
 {% from 'oscar/macros.html' import icon %}
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
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
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 View File

1
 {% from 'oscar/macros.html' import icon %}
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
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
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 View File

1
 {% from 'oscar/macros.html' import icon %}
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
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
5
 {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
6
 <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
7
 
7
 
8
 <div class="container-fluid">
8
 <div class="container-fluid">
9
     <div class="row">
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
         {% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8 result-content">{{ result.content|safe }}</p>{% endif %}
11
         {% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8 result-content">{{ result.content|safe }}</p>{% endif %}
12
     </div>
12
     </div>
13
 </div>
13
 </div>

+ 8
- 8
searx/webapp.py View File

65
 
65
 
66
 babel = Babel(app)
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
 cookie_max_age = 60 * 60 * 24 * 365 * 23  # 23 years
75
 cookie_max_age = 60 * 60 * 24 * 365 * 23  # 23 years
73
 
76
 
233
         else:
236
         else:
234
             result['pretty_url'] = result['url']
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
         # TODO, check if timezone is calculated right
239
         # TODO, check if timezone is calculated right
241
         if 'publishedDate' in result:
240
         if 'publishedDate' in result:
242
             result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')
241
             result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')
289
         suggestions=search.suggestions,
288
         suggestions=search.suggestions,
290
         answers=search.answers,
289
         answers=search.answers,
291
         infoboxes=search.infoboxes,
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