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