Apply relative link fixer to <img> and other media too.
This commit is contained in:
parent
644f801e03
commit
d939b22e38
1 changed files with 18 additions and 12 deletions
|
@ -123,18 +123,24 @@ 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):
|
||||||
for link in links:
|
links = soup.find_all(tagname)
|
||||||
href = link['href']
|
for link in links:
|
||||||
if '://' in href:
|
href = link[attribute]
|
||||||
continue
|
if '://' in href:
|
||||||
if href.startswith('/'):
|
continue
|
||||||
continue
|
if href.startswith('/'):
|
||||||
href = folder.join(href)
|
continue
|
||||||
href = '/' + href.relative_to(writing_rootdir.parent, simple=True)
|
href = folder.join(href)
|
||||||
if not href.startswith('/writing/'):
|
href = '/' + href.relative_to(writing_rootdir.parent, simple=True)
|
||||||
raise ValueError('Somethings wrong')
|
if not href.startswith('/writing/'):
|
||||||
link['href'] = href
|
raise ValueError('Somethings wrong')
|
||||||
|
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):
|
||||||
|
|
Loading…
Reference in a new issue