Skip to content

Commit cf6a013

Browse files
committed
Merge pull request #10 from deconst/search-query-fixes
Touching up the query page
2 parents 316bfae + 1b40d31 commit cf6a013

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

config/rewrites.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"toPort": "20094",
99
"rewrite": false,
1010
"status": 302
11-
}
11+
},
12+
{
13+
"description": "Force trailing slash",
14+
"from": "\\/([a-zA-Z0-9%_-]*?[^/])$",
15+
"to": "/$1/",
16+
"rewrite": false,
17+
"status": 301
18+
},
1219
]
1320
}

templates/deconst.horse/search.html

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
{% extends "_layouts/base.html" %}
22

33
{% set query = deconst.request.query %}
4-
{% set r = query.q|search(query.page) %}
54

65
{% block body %}
7-
<h1>{{ r.total }} results found</h1>
6+
<form action="get">
7+
<input type="text" value="{{ query.q }}" placeholder="Search">
8+
<input type="submit" value="Go">
9+
</form>
810

9-
{% for result in r.results %}
10-
<div class="result">
11-
<a href="{{ result.url }}">{{ result.title }}</a>
12-
<p>{{ result.excerpt }}</p>
13-
</div>
14-
{% else %}
15-
<p class="explanation">
16-
No results found.
17-
</p>
18-
{% endfor %}
11+
{% if query.q %}
12+
{% set r = query.q|search(query.page) %}
13+
<h1>{{ r.total }} results found</h1>
1914

20-
{% if r.pages > 1 %}
21-
<div class="pager">
22-
{% for p in range(1, r.pages) %}
23-
<a href="/search?q={{ query.q }}&page={{ p }}">{{ p }}</a>
24-
{%- if not loop.last %} | {% endif -%}
25-
{% endfor %}
26-
</div>
15+
{% for result in r.results %}
16+
<div class="result">
17+
<a href="{{ result.url }}">{{ result.title }}</a>
18+
<p>{{ result.excerpt }}</p>
19+
</div>
20+
{% else %}
21+
<p class="explanation">
22+
No results found.
23+
</p>
24+
{% endfor %}
25+
26+
{% if r.pages > 1 %}
27+
<div class="pager">
28+
{% for p in range(1, r.pages) %}
29+
<a href="/search/?q={{ query.q }}&page={{ p }}">{{ p }}</a>
30+
{%- if not loop.last %} | {% endif -%}
31+
{% endfor %}
32+
</div>
33+
{% endif %}
2734
{% endif %}
2835
{% endblock %}

0 commit comments

Comments
 (0)