Overview main page: img link to publication pages

pull/9/head
Castro0o 4 years ago
parent 11fe0bf03b
commit e1fb598cf4

@ -68,23 +68,20 @@ def filenameforlink(href):
def rewriteimglinks(tree, page):
#on Overview_main_page
# add link to publication on <a><img>
# invoke after img src have be rewritten
# remove links to wiki File: pages
for a in tree.findall(".//a[@class='image']"): # select img wrapping a
href = a.attrib.get('href')
if a.findall(".//img"): # ensure a has child: img
if page.name == 'Overview main page':
img = a.find(".//img")
img_src = img.attrib['src']
a.attrib['href'] = img_src
else:
# invoke after img src has been rewritten
# To: remove links to wiki File on all pages
# but Overview_main_page page where link to publication page is added
if page.name == 'Overview main page':
for div_parent in tree.findall(".//div[@class='tooltip']"):
anchor_of_img = div_parent.find(".//div/a")
if anchor_of_img.find(".//img") is not None: # <a> needs child <img>
a_tag = div_parent.find(".//p/span/a")
publication_href = a_tag.attrib.get('href')
anchor_of_img.attrib['href'] = publication_href
else:
for a in tree.findall(".//a[@class='image']"): # select img wrapping a
if a.findall(".//img"): # ensure a has child: img
a.attrib['href'] = 'javascript:void(0);' # disable href
print(a)
print(ET.tostring(a, method="html", encoding="unicode"))
return tree
def rewritelinks(html):

Loading…
Cancel
Save