Browse Source

[enh] add official site link to the top of the infobox - closes #1644

Adam Tauber 4 years ago
parent
commit
29960aa1d9
2 changed files with 7 additions and 4 deletions
  1. 6 4
      searx/engines/wikidata.py
  2. 1 0
      searx/templates/oscar/infobox.html

+ 6 - 4
searx/engines/wikidata.py

@@ -414,11 +414,13 @@ def add_url(urls, result, id_cache, property_id=None, default_label=None, url_pr
     # append urls
     for url in links:
         if url is not None:
-            urls.append({'title': default_label or label,
-                         'url': url})
+            u = {'title': default_label or label, 'url': url}
+            if property_id == 'P856':
+                u['official'] = True
+                u['domain'] = url.split('/')[2]
+            urls.append(u)
             if results is not None:
-                results.append({'title': default_label or label,
-                                'url': url})
+                results.append(u)
 
 
 def get_imdblink(result, url_prefix):

+ 1 - 0
searx/templates/oscar/infobox.html

@@ -2,6 +2,7 @@
 <div class="panel panel-default infobox">
     <div class="panel-heading">{{- "" -}}
         <h4 class="panel-title infobox_part"><bdi>{{ infobox.infobox }}</bdi></h4>{{- "" -}}
+        {% for u in infobox.urls %}{% if u.official %} <a href="{{ u.url }}">{{ u.domain }}</a>{% endif %}{% endfor %}
     </div>
     <div class="panel-body">
         {% if infobox.img_src %}<img class="img-responsive center-block infobox_part" src="{{ image_proxify(infobox.img_src) }}" alt="{{ infobox.infobox }}" />{% endif %}