diff --git a/flamingo/plugins/feeds.py b/flamingo/plugins/feeds.py index 41b5e71..ccd746a 100644 --- a/flamingo/plugins/feeds.py +++ b/flamingo/plugins/feeds.py @@ -1,10 +1,32 @@ import logging +from urllib.parse import urljoin +from bs4 import BeautifulSoup from feedgen.feed import FeedGenerator logger = logging.getLogger('flamingo.plugins.Feeds') +def make_urls_absolute(html, base_url): + soup = BeautifulSoup(html, 'html.parser') + + for element in soup.find_all(['img', 'script', 'asciinema-player']): + try: + element['src'] = urljoin(base_url, element['src']) + except KeyError: + # not all elements might have a src attribute + continue + + for link in soup.find_all('a'): + try: + link['href'] = urljoin(base_url, link['href']) + except KeyError: + # not all elements might have an href attribute + continue + + return str(soup) + + class Feeds: def pre_build(self, context): FEEDS_DOMAIN = getattr(context.settings, 'FEEDS_DOMAIN', '/') @@ -122,6 +144,8 @@ def pre_build(self, context): if i['content_body']: exitcode, output = context.pre_render(i) + output = make_urls_absolute(output, fe_link['href']) + if 'html_filter' in feed_config: output = feed_config['html_filter'](output) fe.content(output, type='html')