gemivim

VIM plugin for Gemini browsing
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit ee354f5c540c9c374d72cb0eca85463982bd2ca0
parent a6a090918733cd6b58f360ad63c599f8e3f9727b
Author: René Wagner <rwa@clttr.info>
Date:   Mon, 28 Aug 2023 19:04:10 +0200

improve handling of relative links

Relative links without prefix and relative links with ./ prefix
were treated incorrect, leading to wrong URIs being generated.

Due to a drift to dynamic capsules backed by CGI scripts some assumptions needed to be revised:
- getting the current URI with <cfile> led to query strings being skipped.
- appending index.gmi whenever a file does not end with .gmi did not honor
query strings as well, that results in strange file names.
Both issues have been fixed.

Diffstat:
Mautoload/gemivim.vim | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/autoload/gemivim.vim b/autoload/gemivim.vim @@ -22,8 +22,8 @@ endfunction function! s:tmp_file_name(url, mime_type) let l:file = g:tmp_prefix . substitute(a:url, 'gemini://', '', 'g') - if a:mime_type ==# 'text/gemini' && a:url !~# '.*\.gmi$' - return l:file . '/index.gmi' + if a:mime_type ==# 'text/gemini' && a:url =~# '/$' + return l:file . 'index.gmi' else return l:file endif @@ -129,11 +129,15 @@ function! s:base_url(url) return substitute(l:url, '.gmi$', '', 'g') endfunction +function! s:base_path(url) + return substitute(a:url, '[^/]*$', '', '') +endfunction + function! s:relative_url(from, relative) if a:relative =~# '^/.*' return s:base_url(a:from) . a:relative else - return a:from . a:relative + return s:base_path(a:from) . substitute(a:relative, '^./', '', '') endif endfunction @@ -151,12 +155,12 @@ function! gemivim#Open() endfunction function! gemivim#GX() - let url = expand('<cfile>') + let url = expand('<cWORD>') if url =~? 'gemini://.*' call gemivim#Get(url) elseif url =~? 'http://.*' || url =~? 'https://.*' || url =~? 'gopher://.*' call s:error_msg('Not a gemini url') - elseif &filetype =~# '\(gmi\|gemini\)' || bufname() =~? '.*\.\(gmi\|gemini\)$' + else call gemivim#Get(s:relative_url(s:current_url(), url)) endif endfunction