(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)
(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?
)
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")