Apply relative link fixer to <img> and other media too.

This commit is contained in:
Ethan Dalool 2020-06-04 11:14:07 -07:00
parent 644f801e03
commit d939b22e38

View file

@ -123,9 +123,10 @@ def soup_adjust_relative_links(soup, md_file, repo_path):
relative links into absolute links starting from /writing. relative links into absolute links starting from /writing.
''' '''
folder = pathclass.Path(md_file.parent, force_sep='/') folder = pathclass.Path(md_file.parent, force_sep='/')
links = soup.find_all('a') def fixby(tagname, attribute):
links = soup.find_all(tagname)
for link in links: for link in links:
href = link['href'] href = link[attribute]
if '://' in href: if '://' in href:
continue continue
if href.startswith('/'): if href.startswith('/'):
@ -134,7 +135,12 @@ def soup_adjust_relative_links(soup, md_file, repo_path):
href = '/' + href.relative_to(writing_rootdir.parent, simple=True) href = '/' + href.relative_to(writing_rootdir.parent, simple=True)
if not href.startswith('/writing/'): if not href.startswith('/writing/'):
raise ValueError('Somethings wrong') raise ValueError('Somethings wrong')
link['href'] = href link[attribute] = href
fixby('a', 'href')
fixby('img', 'src')
fixby('video', 'src')
fixby('audio', 'src')
fixby('source', 'src')
class Article: class Article:
def __init__(self, md_file): def __init__(self, md_file):