X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=1988656530764d5554c496b37a9ff710f5c9b0cb;hp=56c5996c16ebc26a805ad441e318ff3d9a68f75d;hb=e810b9831045c588543454cce81d4d9e6d13ffdc;hpb=e8c010a9f70321b2671c2cf6b4cba2db8320e319 diff --git a/elpher.el b/elpher.el index 56c5996..1988656 100644 --- a/elpher.el +++ b/elpher.el @@ -307,9 +307,25 @@ requiring gopher-over-TLS." (defun elpher-address-to-url (address) "Get string representation of ADDRESS, or nil if ADDRESS is special." - (if (not (elpher-address-special-p address)) - (url-encode-url (url-recreate-url address)) - nil)) + (if (elpher-address-special-p address) + nil + (let* ((port (url-port address)) + (address-to-convert + (if (= port 0) + address + (let ((address-copy (seq-copy address)) + (protocol (url-type address))) + (if (or (and (equal protocol "gopher") + (= port 70)) + (and (equal protocol "gemini") + (= port 1965)) + (and (equal protocol "http") + (= port 80)) + (and (equal protocol "finger") + (= port 79))) + (setf (url-port address-copy) 0)) + address-copy)))) + (url-encode-url (url-recreate-url address-to-convert))))) (defun elpher-address-type (address) "Retrieve type of ADDRESS object. @@ -1116,17 +1132,18 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (defun elpher-address-from-gemini-url (url) "Extract address from URL with defaults as per gemini map files." - (let ((address (url-generic-parse-url url))) + (let ((address (url-generic-parse-url url)) + (current-address (elpher-page-address elpher-current-page))) (unless (and (url-type address) (not (url-fullness address))) ;avoid mangling mailto: urls (setf (url-fullness address) t) (if (url-host address) ;if there is an explicit host, filenames are absolute (if (string-empty-p (url-filename address)) (setf (url-filename address) "/")) ;ensure empty filename is marked as absolute - (setf (url-host address) (url-host (elpher-page-address elpher-current-page))) + (setf (url-host address) (url-host current-address)) + (setf (url-port address) (url-port current-address)) (unless (string-prefix-p "/" (url-filename address)) ;deal with relative links (setf (url-filename address) - (concat (file-name-directory - (url-filename (elpher-page-address elpher-current-page))) + (concat (file-name-directory (url-filename current-address)) (url-filename address))))) (unless (url-type address) (setf (url-type address) "gemini"))