From: Armaan Bhojwani Date: Sun, 28 Nov 2021 04:59:36 +0000 (-0500) Subject: Implement pagination X-Git-Tag: 0.1~2 X-Git-Url: https://git.armaanb.net/?p=bettersearch.git;a=commitdiff_plain;h=43a001ece8e3b2ab9f103f822afd14eeb2e3f42e Implement pagination --- diff --git a/TODO b/TODO index 141a0f2..ad2c40a 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ -* Pagination * Customizeable searx instance diff --git a/server.rkt b/server.rkt index 42da286..01177fe 100644 --- a/server.rkt +++ b/server.rkt @@ -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 @@ } + +

+ + Previous + + +Next + +