Quellcode durchsuchen

oscar template: implement first version of results page

* implement results page
* improve search form template
* implement all result_templates
* fix youtube engine
Thomas Pointhuber vor 10 Jahren
Ursprung
Commit
f3b565e17e

+ 1
- 5
searx/engines/youtube.py Datei anzeigen

@@ -69,12 +69,8 @@ def response(resp):
69 69
 
70 70
         if result['media$group']['media$thumbnail']:
71 71
             thumbnail = result['media$group']['media$thumbnail'][0]['url']
72
-            content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, thumbnail)  # noqa
73 72
 
74
-        if content:
75
-            content += '<br />' + result['content']['$t']
76
-        else:
77
-            content = result['content']['$t']
73
+        content = result['content']['$t']
78 74
 
79 75
         # append result
80 76
         results.append({'url': url,

+ 26
- 0
searx/static/oscar/css/oscar.css Datei anzeigen

@@ -25,3 +25,29 @@ input[type=checkbox]:checked ~ .label_hide_if_checked {
25 25
 input[type=checkbox]:not(:checked) ~ .label_hide_if_not_checked {
26 26
   display:none;
27 27
 }
28
+
29
+.search_categories {
30
+  margin:10px 0;
31
+}
32
+
33
+.result-default {
34
+    clear: both;
35
+}
36
+
37
+.result-images {
38
+    float: left !important;
39
+}
40
+
41
+.result-videos {
42
+    clear: both;
43
+}
44
+
45
+.result-torrents {
46
+    clear: both;
47
+}
48
+
49
+.img-thumbnail {
50
+    margin: 5px;
51
+    max-height: 128px;
52
+    min-height: 128px;
53
+}

+ 1
- 1
searx/templates/oscar/index.html Datei anzeigen

@@ -8,7 +8,7 @@
8 8
     </div>
9 9
     <div class="row">
10 10
         <div class="text-center col-sm-12 col-md-12">
11
-            {% include 'oscar/search.html' %}
11
+            {% include 'oscar/search_full.html' %}
12 12
         </div>
13 13
     </div>
14 14
 </div>

+ 8
- 0
searx/templates/oscar/result_templates/default.html Datei anzeigen

@@ -0,0 +1,8 @@
1
+<h3><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
2
+
3
+{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.publishedDate }}" pubdate>{{ result.publishedDate }}</time>{% endif %}
4
+
5
+{% if result.content %}<p>{{ result.content|safe }}</p>{% endif %}
6
+
7
+<span class="label label-default pull-right">{{ result.engine }}</span>
8
+<p class="text-muted">{% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{ theme }}/img/icon_{{ result['favicon'] }}.ico" />{% endif %} {{ result.pretty_url }}</p>

+ 21
- 0
searx/templates/oscar/result_templates/images.html Datei anzeigen

@@ -0,0 +1,21 @@
1
+<a href="#" data-toggle="modal" data-target="#modal-{{ index }}">
2
+    <img src="{{ result.img_src }}" alt="{{ result.title|e }}" class="img-thumbnail">
3
+</a>
4
+
5
+<div class="modal fade" id="modal-{{ index }}" tabindex="-1" role="dialog" aria-hidden="true">
6
+    <div class="modal-dialog">
7
+        <div class="modal-content">
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>
10
+                <h4 class="modal-title">{{ result.title|striptags }}</h4>
11
+            </div>
12
+            <div class="modal-body">
13
+                <img class="img-responsive center-block" src="{{ result.img_src }}" alt="{{ result.title }}">
14
+            </div>
15
+            <div class="modal-footer">
16
+                <a href="{{ result.img_src }}" class="btn btn-default">{{ _('Get image') }}</a>
17
+                <a href="{{ result.url }}" class="btn btn-default">{{ _('View source') }}</a>
18
+            </div>
19
+        </div>
20
+    </div>
21
+</div>

+ 14
- 0
searx/templates/oscar/result_templates/torrent.html Datei anzeigen

@@ -0,0 +1,14 @@
1
+{% from 'oscar/macros.html' import icon %}
2
+
3
+<h3><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
4
+
5
+{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.publishedDate }}" pubdate>{{ result.publishedDate }}</time>{% endif %}
6
+
7
+<p>{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span>, {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span></p>
8
+
9
+<p><a href="{{ result.magnetlink }}" class="magnetlink">{{ icon('magnet') }} magnet link</a></p>
10
+
11
+{% if result.content %}<p>{{ result.content|safe }}</p>{% endif %}
12
+
13
+<span class="label label-default pull-right">{{ result.engine }}</span>
14
+<p class="text-muted">{% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{ theme }}/img/icon_{{ result['favicon'] }}.ico" />{% endif %} {{ result.pretty_url }}</p>

+ 13
- 0
searx/templates/oscar/result_templates/videos.html Datei anzeigen

@@ -0,0 +1,13 @@
1
+<h3><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
2
+    
3
+{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.publishedDate }}" pubdate>{{ result.publishedDate }}</time>{% endif %}
4
+    
5
+<div class="container-fluid">
6
+    <div class="row">
7
+        <img class="thumbnail col-xs-6 col-sm-4 col-md-4" src="{{ result.thumbnail|safe }}" />
8
+        {% if result.content %}<p class="col-xs-12 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif %}
9
+    </div>
10
+</div>
11
+    
12
+<span class="label label-default pull-right">{{ result.engine }}</span>
13
+<p class="text-muted">{% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" />{% endif %} {{ result.pretty_url }}</p>

+ 22
- 0
searx/templates/oscar/results.html Datei anzeigen

@@ -0,0 +1,22 @@
1
+{% extends "oscar/base.html" %}
2
+{% block title %}{{ q }} - {% endblock %}
3
+{% block content %}
4
+    <div class="row">
5
+        <div class="col-sm-8" id="main_results">
6
+            <h1 class="sr-only">{{ _('Search results') }}</h1>
7
+            {% include 'oscar/search.html' %}
8
+            
9
+            {% for result in results %}
10
+            <div class="result {% if result['template'] %}result-{{ result.template|replace('.html', '') }}{% else %}result-default{% endif %}">
11
+                {% set index = loop.index %}
12
+                {% if result.template %}{% include 'oscar/result_templates/'+result['template'] %}{% else %}{% include 'oscar/result_templates/default.html' %}{% endif %}
13
+            </div>
14
+            {% endfor %}
15
+            
16
+            <div class="clearfix"></div>
17
+    
18
+        </div>
19
+        <div class="col-sm-4" id="sidebar_results">
20
+        </div>
21
+    </div>
22
+{% endblock %}

+ 4
- 9
searx/templates/oscar/search.html Datei anzeigen

@@ -1,17 +1,12 @@
1 1
 {% from 'oscar/macros.html' import icon %}
2
-
3 2
 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
4
-    <div class="input-group col-md-8 col-md-offset-2">
5
-        <input type="search" name="q" class="form-control input-lg" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
3
+    <div class="input-group col-sm-12">
4
+        <input type="search" name="q" class="form-control" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
6 5
         <span class="input-group-btn">
7
-            <button type="submit" class="btn btn-default input-lg">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
6
+            <button type="submit" class="btn btn-default">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
8 7
         </span>
9 8
     </div>
10
-
11
-    <button type="button" class="btn btn-link btn-collapse center-block collapsed" data-toggle="collapse" data-target="#search_categories" data-btn-text-collapsed="{{ _('Show search filters') }}" data-btn-text-not-collapsed="{{ _('Hide search filters') }}">{{ _('Show search filters') }}</button>
12
-    <div class="row collapse" id="search_categories">
13
-        <div class="col-md-12 text-center">
9
+    <div class="search_categories">
14 10
             {% include 'oscar/categories.html' %}
15
-        </div>
16 11
     </div><!-- / #search_categories -->
17 12
 </form><!-- / #search_form_full -->

+ 17
- 0
searx/templates/oscar/search_full.html Datei anzeigen

@@ -0,0 +1,17 @@
1
+{% from 'oscar/macros.html' import icon %}
2
+
3
+<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
4
+    <div class="input-group col-md-8 col-md-offset-2">
5
+        <input type="search" name="q" class="form-control input-lg" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
6
+        <span class="input-group-btn">
7
+            <button type="submit" class="btn btn-default input-lg">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
8
+        </span>
9
+    </div>
10
+
11
+    <button type="button" class="btn btn-link btn-collapse center-block collapsed" data-toggle="collapse" data-target="#search_categories" data-btn-text-collapsed="{{ _('Show search filters') }}" data-btn-text-not-collapsed="{{ _('Hide search filters') }}">{{ _('Show search filters') }}</button>
12
+    <div class="row collapse" id="search_categories">
13
+        <div class="col-md-12 text-center">
14
+            {% include 'oscar/categories.html' %}
15
+        </div>
16
+    </div><!-- / #search_categories -->
17
+</form><!-- / #search_form_full -->