feat: Add alternate link tag to feeds

This commit is contained in:
Leon
2025-07-19 19:39:05 +02:00
parent 120718987e
commit 0062441a2d
3 changed files with 7 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ def generate_feed(db: Session, newsletter_id: str):
fg.logo(logo_url)
fg.icon(icon_url)
fg.link(href=feed_url, rel="self")
fg.link(href=settings.app_base_url, rel="alternate")
sender_emails = ", ".join([s.email for s in newsletter.senders])
fg.description(f"A feed of newsletters from {sender_emails}")

View File

@@ -182,6 +182,11 @@ def test_get_newsletter_feed(client: TestClient):
root = ET.fromstring(response.text)
# Atom feed uses a namespace, so we need to include it in our tag searches
ns = {"atom": "http://www.w3.org/2005/Atom"}
links = root.findall("atom:link", ns)
assert any(
link.get("rel") == "alternate" and link.get("href") == "http://localhost:8000"
for link in links
)
logo = root.find("atom:logo", ns)
assert logo is not None
assert logo.text == "http://localhost:8000/logo.png"

View File

@@ -40,6 +40,7 @@ def test_generate_feed(db_session: Session):
# In a real scenario, you'd use an XML parser to validate structure and content more thoroughly
assert f"<title>{newsletter.name}</title>" in feed_xml.decode()
assert f"<id>urn:letterfeed:newsletter:{newsletter.id}</id>" in feed_xml.decode()
assert '<link href="http://localhost:8000" rel="alternate"/>' in feed_xml.decode()
assert "<logo>http://localhost:8000/logo.png</logo>" in feed_xml.decode()
assert "<icon>http://localhost:8000/favicon.ico</icon>" in feed_xml.decode()
assert "<title>First Entry</title>" in feed_xml.decode()