handle relative links and unspecified schemes
This commit is contained in:
19
gem300.rkt
19
gem300.rkt
@@ -3,6 +3,8 @@
|
||||
(require (prefix-in net: "net.rkt")
|
||||
(prefix-in gmi: "gmi.rkt"))
|
||||
|
||||
(require net/url-string)
|
||||
|
||||
;; global state variable which will be an input port containing the
|
||||
;; rendered out gemtext document as it shall be shown to the user
|
||||
(define document-buffer null)
|
||||
@@ -10,8 +12,15 @@
|
||||
;; global state which will be the document structure, before rendering
|
||||
(define document null)
|
||||
|
||||
;; global state for the url of the currently visited document
|
||||
(define current-url null)
|
||||
|
||||
(define (go-cmd url)
|
||||
(if (non-empty-string? url)
|
||||
(let ()
|
||||
(when (not (string-contains? url "://"))
|
||||
(set! url (string-append "gemini://" url)))
|
||||
|
||||
(let-values ([(status meta c-in) (net:get url)])
|
||||
(let-values ([(doc) (gmi:parse (port->lines c-in))]
|
||||
[(db-in db-out) (make-pipe #f)])
|
||||
@@ -22,10 +31,12 @@
|
||||
(parameterize ([current-output-port db-out])
|
||||
(gmi:render doc))
|
||||
|
||||
(set! current-url url)
|
||||
|
||||
(let ([remaining (pipe-content-length db-in)])
|
||||
(printf "document retrieved. ~a bytes\n" remaining))
|
||||
|
||||
(next-cmd)))
|
||||
(next-cmd))))
|
||||
|
||||
(displayln "go where?")))
|
||||
|
||||
@@ -43,7 +54,11 @@
|
||||
(printf "~a bytes remaining\n" remaining)))
|
||||
|
||||
(define (visit-cmd line)
|
||||
(go-cmd (gmi:match-link document (string->number line))))
|
||||
(define url (gmi:match-link document (string->number line)))
|
||||
(set! url
|
||||
(url->string (combine-url/relative (string->url current-url)
|
||||
url)))
|
||||
(go-cmd url))
|
||||
|
||||
(define (repl)
|
||||
(display "G-300 > ")
|
||||
|
Reference in New Issue
Block a user