From 43897cc96157572b37da3e3a96a65fe4b6c5b06b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 11 Apr 2024 02:18:56 +0200 Subject: [PATCH] Don't prepend images with the blog base URL if they are already full URLs --- madblog/routes.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/madblog/routes.py b/madblog/routes.py index 9a42ff7..3a1196a 100644 --- a/madblog/routes.py +++ b/madblog/routes.py @@ -1,5 +1,7 @@ import os +import re from typing import Optional +from urllib.parse import urljoin from flask import ( jsonify, @@ -167,15 +169,22 @@ def rss_route(): base_link=config.link, title=page.get("title", "[No Title]"), link=page.get("uri", ""), - published=page["published"].strftime( - "%a, %d %b %Y %H:%M:%S GMT" - ) - if "published" in page - else "", - content=page.get("description", "") - if short_description - else page.get("content", ""), - image=page.get("image", ""), + published=( + page["published"].strftime("%a, %d %b %Y %H:%M:%S GMT") + if "published" in page + else "" + ), + content=( + page.get("description", "") + if short_description + else page.get("content", "") + ), + image=( + urljoin(config.link, page["image"]) + if page.get("image") + and not re.search(r"^https?://", page["image"]) + else page.get("image", "") + ), ) for _, page in pages ]