On Fr, 24 Nov 2017, Bram Moolenaar wrote:
>
> Christian Brabandt wrote:
>
> > Bram,
> > I thought about adding a test to check the availability of URLs. Here is
> > a test script. However I did not add it to the test suite, as it takes
> > some time. But it already finds some unreachable URLs.
>
> I like the idea, but the script does not appear to work.
>
> I don't have curl but do have wget, I tried to make it work with that.
> Unforrunately wget doesn't appear to have an option to only fetch the
> header.
>
> It seems this line should be removed:
>
> %d
Here is an updated version, that should work with wget. The %d was only
at the wrong line I think.
Christian
--
Lieber gut drauf, als schlecht dran.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
" Test for URLs in help documents
" Opens a new window with all found URLS followed by return code from curl
" (anything other than 0 means unreachable)
func! Test_check_URLs()
if (!executable('curl') && !executable('wget')) || has("win32")
return
endif
let g:pat='\(https\?\|ftp\)://[^\t* ]\+'
exe 'helpgrep' g:pat
helpc
let urls = map(getqflist(), 'v:val.text')
let urls = map(urls, {key, val -> matchstr(val, g:pat)})
" remove examples like user@host (invalid urls)
let urls = filter(urls, 'v:val !~ "@"')
" Remove example URLs which are invalid
let urls = filter(urls, {key, val -> val !~
'\<\(\(my\|some\)\?host\|machine\|hostname\|file\)\>'})
new
put =urls
" remove some more invalid items
" empty lines
v/./d
" remove # anchors
%s/#.*$//e
" remove trailing stuff (parenthesis, dot, comma, quotes)
g/^h/s#[.,)'"/>][:.]\?$##
g#^[hf]t\?tp:/\(/\?\.*\)$#d
g/=$/d
let a = getline(1,'$')
let a = uniq(sort(a))
%d
call setline(1, a)
%s/.*/\=TestURL(submatch(0))/
endfunc
func! TestURL(url)
" Note: does not follow redirects!
" Relies on the return code to determine whether a page is valid
echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url)
let url=shellescape(a:url)
if executable('curl')
call system('curl --silent --fail --output /dev/null --head '. url)
elseif executable('wget')
call system('wget -q -S --spider --max-redirect=0 '. url)
endif
return printf("%s %d", a:url, v:shell_error)
endfunc