From 73c8e9da3928da1856f1a0bd944c7ea51ad935d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Mon, 27 Apr 2026 19:22:19 +0200 Subject: [PATCH] Add meta tags for better previews when sharing links --- discord_rss_bot/templates/add.html | 5 +- discord_rss_bot/templates/add_webhook.html | 5 +- discord_rss_bot/templates/base.html | 31 +++++- discord_rss_bot/templates/blacklist.html | 5 +- discord_rss_bot/templates/custom.html | 5 +- discord_rss_bot/templates/embed.html | 5 +- discord_rss_bot/templates/feed.html | 5 +- discord_rss_bot/templates/index.html | 6 + discord_rss_bot/templates/search.html | 7 +- discord_rss_bot/templates/settings.html | 5 +- .../templates/webhook_entries.html | 5 +- discord_rss_bot/templates/webhooks.html | 5 +- discord_rss_bot/templates/whitelist.html | 5 +- tests/test_main.py | 105 ++++++++++++++++++ 14 files changed, 177 insertions(+), 22 deletions(-) diff --git a/discord_rss_bot/templates/add.html b/discord_rss_bot/templates/add.html index 5e5ba51..760a228 100644 --- a/discord_rss_bot/templates/add.html +++ b/discord_rss_bot/templates/add.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | Add new feed + Add Feed | discord-rss-bot {% endblock title %} +{% block description %} + Add a new RSS or Atom feed and attach it to a Discord webhook for delivery. +{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/add_webhook.html b/discord_rss_bot/templates/add_webhook.html index 5948395..72fa673 100644 --- a/discord_rss_bot/templates/add_webhook.html +++ b/discord_rss_bot/templates/add_webhook.html @@ -1,7 +1,6 @@ {% extends "base.html" %} -{% block title %} -| Add new webhook -{% endblock title %} +{% block title %}Add Webhook | discord-rss-bot{% endblock title %} +{% block description %}Register a Discord webhook so feeds can post updates into your server or thread.{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/base.html b/discord_rss_bot/templates/base.html index 9146b35..1b51519 100644 --- a/discord_rss_bot/templates/base.html +++ b/discord_rss_bot/templates/base.html @@ -3,17 +3,38 @@ + + {% block title %} + discord-rss-bot + {% endblock title %} + + content="{% block description %}Manage RSS feeds, webhooks, filters, and message delivery settings for Discord updates from a single dashboard.{% endblock description %}" /> + {% set page_title = self.title() | striptags | trim %} + {% set page_description = self.description() | striptags | trim %} + {% set canonical_url = request.url %} + {% set social_image = request.base_url ~ "static/favicon.ico" %} + + + + + + + + + + + + + + + + - discord-rss-bot - {% block title %} - {% endblock title %} - {% block head %} {% endblock head %} diff --git a/discord_rss_bot/templates/blacklist.html b/discord_rss_bot/templates/blacklist.html index 54e1220..8f296d2 100644 --- a/discord_rss_bot/templates/blacklist.html +++ b/discord_rss_bot/templates/blacklist.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | Blacklist + Blacklist: {{ feed.title if feed.title else feed.url }} | discord-rss-bot {% endblock title %} +{% block description %} + Block matching entries from {{ feed.title if feed.title else feed.url }} before they are delivered to Discord. +{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/custom.html b/discord_rss_bot/templates/custom.html index 48cb3bc..3146718 100644 --- a/discord_rss_bot/templates/custom.html +++ b/discord_rss_bot/templates/custom.html @@ -1,7 +1,6 @@ {% extends "base.html" %} -{% block title %} -| Custom message -{% endblock title %} +{% block title %}Message Template: {{ feed.title if feed.title else feed.url }} | discord-rss-bot{% endblock title %} +{% block description %}Customize the plain text Discord message template for {{ feed.title if feed.title else feed.url }}.{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/embed.html b/discord_rss_bot/templates/embed.html index ff42e16..af800e3 100644 --- a/discord_rss_bot/templates/embed.html +++ b/discord_rss_bot/templates/embed.html @@ -1,7 +1,6 @@ {% extends "base.html" %} -{% block title %} -| Embed -{% endblock title %} +{% block title %}Embed Template: {{ feed.title if feed.title else feed.url }} | discord-rss-bot{% endblock title %} +{% block description %}Customize the Discord embed layout, colors, and media for {{ feed.title if feed.title else feed.url }}.{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/feed.html b/discord_rss_bot/templates/feed.html index 92e0e7b..d04a662 100644 --- a/discord_rss_bot/templates/feed.html +++ b/discord_rss_bot/templates/feed.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | {{ feed.title }} + {{ feed.title if feed.title else feed.url }} | discord-rss-bot {% endblock title %} +{% block description %} + Review feed health, delivery settings, filters, webhook attachment, and update intervals for {{ feed.title if feed.title else feed.url }}. +{% endblock description %} {% block content %}
diff --git a/discord_rss_bot/templates/index.html b/discord_rss_bot/templates/index.html index 6c12656..049d30d 100644 --- a/discord_rss_bot/templates/index.html +++ b/discord_rss_bot/templates/index.html @@ -1,4 +1,10 @@ {% extends "base.html" %} +{% block title %} + Feeds Dashboard | discord-rss-bot +{% endblock title %} +{% block description %} + View configured feeds, broken sources, webhook groups, and delivery status across your Discord RSS bot dashboard. +{% endblock description %} {% block content %}
    diff --git a/discord_rss_bot/templates/search.html b/discord_rss_bot/templates/search.html index b37f988..a83ef79 100644 --- a/discord_rss_bot/templates/search.html +++ b/discord_rss_bot/templates/search.html @@ -1,7 +1,12 @@ {% extends "base.html" %} {% block title %} - | Search + Search + {% if query %}: {{ query }}{% endif %} + | discord-rss-bot {% endblock title %} +{% block description %} + Browse search results for {{ query if query else "your query" }} across tracked feed entries and feeds. +{% endblock description %} {% block content %}
    Your search for "{{ query }}" returned {{ search_amount.total }} results. diff --git a/discord_rss_bot/templates/settings.html b/discord_rss_bot/templates/settings.html index 40fd9d0..1759738 100644 --- a/discord_rss_bot/templates/settings.html +++ b/discord_rss_bot/templates/settings.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | Settings + Settings | discord-rss-bot {% endblock title %} +{% block description %} + Adjust default update intervals, delivery modes, and screenshot layout for feeds managed by your bot. +{% endblock description %} {% block content %}
    diff --git a/discord_rss_bot/templates/webhook_entries.html b/discord_rss_bot/templates/webhook_entries.html index f808e77..b2bb0de 100644 --- a/discord_rss_bot/templates/webhook_entries.html +++ b/discord_rss_bot/templates/webhook_entries.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | {{ webhook_name }} + {{ webhook_name }} | discord-rss-bot {% endblock title %} +{% block description %} + Review webhook settings, attached feeds, and latest entries delivered to {{ webhook_name }}. +{% endblock description %} {% block content %} {% if message %}{% endif %}
    diff --git a/discord_rss_bot/templates/webhooks.html b/discord_rss_bot/templates/webhooks.html index d37e390..f1d95ca 100644 --- a/discord_rss_bot/templates/webhooks.html +++ b/discord_rss_bot/templates/webhooks.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | Webhooks + Webhooks | discord-rss-bot {% endblock title %} +{% block description %} + Manage stored Discord webhooks and inspect the delivery endpoints connected to your feeds. +{% endblock description %} {% block content %}
    {% for hook in hooks_with_data %} diff --git a/discord_rss_bot/templates/whitelist.html b/discord_rss_bot/templates/whitelist.html index fd27eb6..4345f72 100644 --- a/discord_rss_bot/templates/whitelist.html +++ b/discord_rss_bot/templates/whitelist.html @@ -1,7 +1,10 @@ {% extends "base.html" %} {% block title %} - | Whitelist + Whitelist: {{ feed.title if feed.title else feed.url }} | discord-rss-bot {% endblock title %} +{% block description %} + Allow only matching entries from {{ feed.title if feed.title else feed.url }} to reach Discord. +{% endblock description %} {% block content %}
    diff --git a/tests/test_main.py b/tests/test_main.py index 1dc7db9..b3b8ad3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -46,6 +46,26 @@ def ensure_preview_feed_exists() -> Reader: return reader +def assert_social_preview_metadata( + response: Response, + *, + title: str, + description: str, +) -> None: + assert response.status_code == 200, f"Expected page to render successfully: {response.text}" + assert f"{title}" in response.text + assert re.search( + rf'', + response.text, + ) + assert f'' in response.text + assert f'' in response.text + assert '' in response.text + assert '' in response.text + assert f'' in response.text + assert f'' in response.text + + def test_search() -> None: """Test the /search page.""" # Remove the feed if it already exists before we run the test. @@ -230,6 +250,91 @@ def test_get() -> None: assert response.status_code == 200, f"/whitelist failed: {response.text}" +def test_views_render_social_preview_metadata() -> None: + client.post(url="/delete_webhook", data={"webhook_url": webhook_url}) + response: Response = client.post( + url="/add_webhook", + data={"webhook_name": webhook_name, "webhook_url": webhook_url}, + ) + assert response.status_code == 200, f"Failed to add webhook: {response.text}" + + feeds: Response = client.get("/") + if feed_url in feeds.text: + client.post(url="/remove", data={"feed_url": feed_url}) + client.post(url="/remove", data={"feed_url": encoded_feed_url(feed_url)}) + + response = client.post(url="/add", data={"feed_url": feed_url, "webhook_dropdown": webhook_name}) + assert response.status_code == 200, f"Failed to add feed: {response.text}" + + assert_social_preview_metadata( + client.get(url="/"), + title="Feeds Dashboard | discord-rss-bot", + description="View configured feeds, broken sources, webhook groups, and delivery status across your Discord RSS bot dashboard.", # noqa: E501 + ) + assert_social_preview_metadata( + client.get(url="/add"), + title="Add Feed | discord-rss-bot", + description="Add a new RSS or Atom feed and attach it to a Discord webhook for delivery.", + ) + assert_social_preview_metadata( + client.get(url="/add_webhook"), + title="Add Webhook | discord-rss-bot", + description="Register a Discord webhook so feeds can post updates into your server or thread.", + ) + assert_social_preview_metadata( + client.get(url="/settings"), + title="Settings | discord-rss-bot", + description="Adjust default update intervals, delivery modes, and screenshot layout for feeds managed by your bot.", # noqa: E501 + ) + assert_social_preview_metadata( + client.get(url="/webhooks"), + title="Webhooks | discord-rss-bot", + description="Manage stored Discord webhooks and inspect the delivery endpoints connected to your feeds.", + ) + assert_social_preview_metadata( + client.get(url="/search", params={"query": "a"}), + title="Search: a | discord-rss-bot", + description="Browse search results for a across tracked feed entries and feeds.", + ) + + feed_response = client.get(url="/feed", params={"feed_url": encoded_feed_url(feed_url)}) + assert feed_response.status_code == 200, f"/feed failed: {feed_response.text}" + assert '' in webhook_entries_response.text + assert ( + f"Review webhook settings, attached feeds, and latest entries delivered to {webhook_name}." + in webhook_entries_response.text + ) + + def test_blacklist_page_uses_live_preview_layout() -> None: ensure_preview_feed_exists()