@@ -214,9 +214,39 @@ auto_repo = function() {
214214
215215# retrieve all CTAN (https) mirrors
216216ctan_mirrors = function () {
217- x = readLines(' https://ctan.org/mirrors/mirmon' )
218- u = xfun :: grep_sub(' .*<TD ALIGN=RIGHT><A HREF="(https://[^"]+)".*' , ' \\ 1' , x )
219- xfun :: raw_string(u )
217+ html = xfun :: file_string(' https://ctan.org/mirrors/' )
218+ r = function (i ) sprintf(' ^(.*>)?\\ s*([^<]+)</h%d>\\ s*(.*)$' , i )
219+ res = unlist(lapply(unlist(strsplit(html , ' <h2[^>]*>' )), function (x ) {
220+ x = unlist(strsplit(x , ' <h3[^>]*>' ))
221+ if (length(x ) < 2 || ! grepl(' </h2>' , x [1 ])) return ()
222+ r2 = r(2 )
223+ continent = gsub(r2 , ' \\ 2' , x [1 ])
224+ x [1 ] = gsub(r2 , ' \\ 3' , x [1 ])
225+ x = x [! grepl(' ^\\ s*$' , x )]
226+ r3 = r(3 )
227+ if (! grepl(r3 , x [1 ])) return ()
228+ country = gsub(r3 , ' \\ 2' , x )
229+ x = gsub(r3 , ' \\ 3' , x )
230+ r4 = r(4 )
231+ x = lapply(x , function (z ) {
232+ z = unlist(strsplit(z , ' <h4[^>]*>' ))
233+ m = regexec(' <a href="(https://[^"]+)"[^>]*>https</a>' , z )
234+ link = unlist(lapply(regmatches(z , m ), `[` , 2 ))
235+ names(link ) = gsub(r4 , ' \\ 2' , z )
236+ link [! is.na(link )]
237+ })
238+ structure(list (structure(x , names = country )), names = continent )
239+ }))
240+ nm = lapply(strsplit(names(res ), ' .' , fixed = TRUE ), function (x ) {
241+ x3 = paste(x [- (1 : 2 )], collapse = ' .' )
242+ r5 = ' .*\\ (|\\ ).*'
243+ x3 = if (grepl(r5 , x3 )) gsub(r5 , ' ' , x3 ) else ' '
244+ c(x [1 ], x [2 ], x3 )
245+ })
246+ nm = do.call(rbind , nm )
247+ res = cbind(nm , unname(res ))
248+ colnames(res ) = c(' Continent' , ' Country/Region' , ' City' , ' URL' )
249+ as.data.frame(res )
220250}
221251
222252# use %APPDATA%/TinyTeX if it exists or doesn't contain spaces or non-ASCII
0 commit comments