From d939b22e388f4f090a53b633f93d59eaff515d84 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 4 Jun 2020 11:14:07 -0700 Subject: [PATCH] Apply relative link fixer to and other media too. --- voussoir.net/writing/generate_site.py | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/voussoir.net/writing/generate_site.py b/voussoir.net/writing/generate_site.py index f8ffd07..5d4a723 100644 --- a/voussoir.net/writing/generate_site.py +++ b/voussoir.net/writing/generate_site.py @@ -123,18 +123,24 @@ def soup_adjust_relative_links(soup, md_file, repo_path): relative links into absolute links starting from /writing. ''' folder = pathclass.Path(md_file.parent, force_sep='/') - links = soup.find_all('a') - for link in links: - href = link['href'] - if '://' in href: - continue - if href.startswith('/'): - continue - href = folder.join(href) - href = '/' + href.relative_to(writing_rootdir.parent, simple=True) - if not href.startswith('/writing/'): - raise ValueError('Somethings wrong') - link['href'] = href + def fixby(tagname, attribute): + links = soup.find_all(tagname) + for link in links: + href = link[attribute] + if '://' in href: + continue + if href.startswith('/'): + continue + href = folder.join(href) + href = '/' + href.relative_to(writing_rootdir.parent, simple=True) + if not href.startswith('/writing/'): + raise ValueError('Somethings wrong') + link[attribute] = href + fixby('a', 'href') + fixby('img', 'src') + fixby('video', 'src') + fixby('audio', 'src') + fixby('source', 'src') class Article: def __init__(self, md_file):