links were broken in v full

This commit is contained in:
Lionel Dricot 2022-03-16 09:47:53 +01:00
parent 452ae6015f
commit 5ddd309bce
2 changed files with 16 additions and 30 deletions

View File

@ -6,6 +6,7 @@
- "cp url X" will copy the URL of link X (suggested by Eoin Carney) - "cp url X" will copy the URL of link X (suggested by Eoin Carney)
- HTML renderering of <pre> has been improved - HTML renderering of <pre> has been improved
- "fold" has been removed as it doesnt work well anyway with our width. - "fold" has been removed as it doesnt work well anyway with our width.
- Improved clipboard URL detection an fixed crash when binary in clipboard
- Fixed crash when chafa is not installed (Thanks Xavier Hinault for the report) - Fixed crash when chafa is not installed (Thanks Xavier Hinault for the report)
- Fixed crash when python-readability not installed (Thanks Nic for the report) - Fixed crash when python-readability not installed (Thanks Nic for the report)

View File

@ -353,10 +353,10 @@ class AbstractRenderer():
return [[self.url,self.get_mime(),self.get_title()]] return [[self.url,self.get_mime(),self.get_title()]]
def is_valid(self): def is_valid(self):
return self.validity return self.validity
def get_links(self): def get_links(self,mode="links_only"):
if self.links == None : if self.links == None :
prepared_body = self.prepare(self.body,mode="links_only") prepared_body = self.prepare(self.body,mode=mode)
results = self.render(prepared_body,mode="links_only") results = self.render(prepared_body,mode=mode)
if results: if results:
self.links = results[1] self.links = results[1]
return self.links return self.links
@ -1018,7 +1018,6 @@ class GeminiItem():
self.name = name self.name = name
self.mime = None self.mime = None
self.renderer = None self.renderer = None
self.links = None
self.body = None self.body = None
parsed = urllib.parse.urlparse(self.url) parsed = urllib.parse.urlparse(self.url)
if "./" in url or url[0] == "/": if "./" in url or url[0] == "/":
@ -1142,7 +1141,6 @@ class GeminiItem():
# If path is too long, we always return True to avoid # If path is too long, we always return True to avoid
# fetching it. # fetching it.
if len(cache) > 259: if len(cache) > 259:
self.links = []
print("We return False because path is too long") print("We return False because path is too long")
return False return False
if os.path.exists(cache) and not os.path.isdir(cache): if os.path.exists(cache) and not os.path.isdir(cache):
@ -1196,8 +1194,13 @@ class GeminiItem():
# This method is used to load once the list of links in a gi # This method is used to load once the list of links in a gi
# Links can be followed, after a space, by a description/title # Links can be followed, after a space, by a description/title
def __make_links(self,links): def get_links(self):
self.links = [] links = []
toreturn = []
if not self.renderer:
self._set_renderer()
if self.renderer:
links = self.renderer.get_links()
for l in links: for l in links:
#split between link and potential name #split between link and potential name
splitted = l.split(maxsplit=1) splitted = l.split(maxsplit=1)
@ -1207,27 +1210,17 @@ class GeminiItem():
newgi = GeminiItem(url,splitted[1]) newgi = GeminiItem(url,splitted[1])
else: else:
newgi = GeminiItem(url) newgi = GeminiItem(url)
self.links.append(newgi) toreturn.append(newgi)
return toreturn
def get_links(self):
if self.links == None:
if not self.renderer:
self._set_renderer()
if self.renderer:
self.__make_links(self.renderer.get_links())
else:
self.links = []
return self.links
def get_link(self,nb): def get_link(self,nb):
# == None allows to return False, even if the list is empty # == None allows to return False, even if the list is empty
if self.links == None: links = self.get_links()
self.get_links() if len(links) < nb:
if len(self.links) < nb:
print("Index too high! No link %s for %s" %(nb,self.url)) print("Index too high! No link %s for %s" %(nb,self.url))
return None return None
else: else:
return self.links[nb-1] return links[nb-1]
def get_subscribe_links(self): def get_subscribe_links(self):
if not self.renderer: if not self.renderer:
@ -1565,7 +1558,6 @@ class GeminiClient(cmd.Cmd):
"width" : 80, "width" : 80,
"auto_follow_redirects" : True, "auto_follow_redirects" : True,
"tls_mode" : "tofu", "tls_mode" : "tofu",
"https_everywhere": False,
"archives_size" : 200, "archives_size" : 200,
"history_size" : 200, "history_size" : 200,
"max_size_download" : 20, "max_size_download" : 20,
@ -1632,12 +1624,6 @@ class GeminiClient(cmd.Cmd):
self._go_to_gi(new_gi) self._go_to_gi(new_gi)
return return
if gi.scheme == "http" and self.options["https_everywhere"] :
newurl = "https" + gi.url[4:]
new_gi = GeminiItem(newurl,name=gi.name)
self._go_to_gi(new_gi)
return
# Use cache or mark as to_fetch if resource is not cached # Use cache or mark as to_fetch if resource is not cached
# Why is this code useful ? It set the mimetype ! # Why is this code useful ? It set the mimetype !
if self.offline_only: if self.offline_only:
@ -1648,7 +1634,6 @@ class GeminiClient(cmd.Cmd):
print("%s not available, marked for syncing"%gi.url) print("%s not available, marked for syncing"%gi.url)
else: else:
print("%s already marked for syncing"%gi.url) print("%s already marked for syncing"%gi.url)
#self.gi = gi
return return
# check if local file exists. # check if local file exists.
if gi.local and not os.path.exists(gi.path): if gi.local and not os.path.exists(gi.path):