diff options
author | Armaan Bhojwani <me@armaanb.net> | 2021-11-27 23:59:36 -0500 |
---|---|---|
committer | Armaan Bhojwani <me@armaanb.net> | 2021-11-27 23:59:36 -0500 |
commit | 43a001ece8e3b2ab9f103f822afd14eeb2e3f42e (patch) | |
tree | c76f3931f139fc8549a6ee4f4d5cffc480d964d3 | |
parent | dfce1b5805e601af45e9bac9bdd9f5095ca92ba9 (diff) | |
download | bettersearch-43a001ece8e3b2ab9f103f822afd14eeb2e3f42e.tar.gz |
Implement pagination
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | server.rkt | 27 | ||||
-rw-r--r-- | templates/search.html | 10 |
3 files changed, 27 insertions, 11 deletions
@@ -1,2 +1 @@ -* Pagination * Customizeable searx instance @@ -30,23 +30,27 @@ (include-template "templates/index.html") (do-footer)))) -(define (search query) +(define (search query pageno) (define engine (string->url (string-append - "https://search.trom.tf/search?format=json&q=" query))) + "https://search.trom.tf/search?format=json&q=" + query + "&pageno=" + pageno + ))) (define response (get-pure-port engine)) (define json-raw (port->string response)) (close-input-port response) (with-input-from-string json-raw (lambda () (read-json)))) -(define (http-response content) ; The 'content' parameter should be a string. +(define (http-response content) (response/full - 200 ; HTTP response code. - #"OK" ; HTTP response message. - (current-seconds) ; Timestamp. - TEXT/HTML-MIME-TYPE ; MIME type for content. - '() ; Additional HTTP heads. - (list ; Content (in bytes) to send to the browser. + 200 + #"OK" + (current-seconds) + TEXT/HTML-MIME-TYPE + '() + (list (string->bytes/utf-8 content)))) (define (do-search req) @@ -57,6 +61,9 @@ (if (non-empty-string? query) (let () + (define pageno (if (exists-binding? 'pageno binds) + (extract-binding/single 'pageno binds) + "1")) (define results (foldr cons '() (filter hash? @@ -76,7 +83,7 @@ ) ht )) - (hash-ref (search query) 'results))))) + (hash-ref (search query pageno) 'results))))) (http-response (string-append (do-head (string-append query " | Web Search")) (include-template "templates/search.html") diff --git a/templates/search.html b/templates/search.html index 58bf146..b3cf72d 100644 --- a/templates/search.html +++ b/templates/search.html @@ -16,3 +16,13 @@ </div> } </dl> + +<p style="text-align: left;"> + <a href="search?q=query&pageno=@(- (string->number pageno) 1)" + style="@(when (equal? pageno "1") "visibility: hidden")"> + Previous + </a> + <span style="float: right;"> +<a href="/search?q=query&pageno=@(+ (string->number pageno) 1)">Next</a> + </span> +</p> |