From 0e698ed143ddc02d77360601fa3c21db6cbda5e0 Mon Sep 17 00:00:00 2001 From: Mandel Olaiya Date: Tue, 16 Jun 2026 21:54:29 +0200 Subject: [PATCH] Fix page heading semantics and localized metadata --- .../engine/pages/base_standard_page.html | 2 + mandelstudio/templates/layout.html | 12 ++++ .../tests/test_localized_navigation_tags.py | 60 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 mandelstudio/tests/test_localized_navigation_tags.py diff --git a/mandelstudio/templates/engine/pages/base_standard_page.html b/mandelstudio/templates/engine/pages/base_standard_page.html index 47ec543..5274a59 100644 --- a/mandelstudio/templates/engine/pages/base_standard_page.html +++ b/mandelstudio/templates/engine/pages/base_standard_page.html @@ -50,7 +50,9 @@ {% endif %}
+ {% if self.body.0.block_type != "saas_hero_banner" %}

{{ self.title }}

+ {% endif %} {% for block in self.body %} {% with scope_class=block.block_type|split:"_"|join:"-" %}
diff --git a/mandelstudio/templates/layout.html b/mandelstudio/templates/layout.html index 8a0ac8c..a44fa0e 100644 --- a/mandelstudio/templates/layout.html +++ b/mandelstudio/templates/layout.html @@ -6,6 +6,7 @@ {% load ocyan_main %} {% load ocyanjson %} {% load static %} +{% load localized_navigation %} {% load wagtailcore_tags wagtailimages_tags wagtailuserbar %} {% block title %}{% firstof page.seo_title self.seo_title page.title self.title shop_name %}{% endblock %} @@ -26,12 +27,23 @@ {% endif %} {{ block.super }} +{% page_canonical_url as canonical_url %} +{% if canonical_url %} + +{% endif %} {% for header_snippet in cookie_jar.activated_snippet_header_templates %} {% include header_snippet %} {% endfor %} {% endblock %} +{% block hreflang %} +{% page_hreflang_links as hreflang_links %} +{% for link in hreflang_links %} + +{% endfor %} +{% endblock %} + {% block layout %} {% if show_basket_popup_setting %} {% esi_fragment "partials/added_success.html" with sessionid=True oscar_open_basket=True request=request csrf_token=csrf_token only %} diff --git a/mandelstudio/tests/test_localized_navigation_tags.py b/mandelstudio/tests/test_localized_navigation_tags.py new file mode 100644 index 0000000..aee66e8 --- /dev/null +++ b/mandelstudio/tests/test_localized_navigation_tags.py @@ -0,0 +1,60 @@ +from types import SimpleNamespace +from unittest import mock + +from django.test import RequestFactory, SimpleTestCase, override_settings + +from mandelstudio.templatetags import localized_navigation + + +@override_settings( + CANONICAL_BASE_URL="https://www.mandelblog.com", + LANGUAGE_CODE="nl", + LANGUAGES=( + ("nl", "Dutch"), + ("en", "English"), + ("de", "German"), + ), +) +class LocalizedNavigationTagTests(SimpleTestCase): + def setUp(self): + self.factory = RequestFactory() + + def test_page_canonical_url_uses_canonical_host_and_page_url(self): + request = self.factory.get("/en/contact/") + page = SimpleNamespace(url="/en/contact/") + + canonical = localized_navigation.page_canonical_url( + {"request": request, "page": page} + ) + + self.assertEqual(canonical, "https://www.mandelblog.com/en/contact/") + + @mock.patch( + "mandelstudio.templatetags.localized_navigation._translated_pages" + ) + def test_page_hreflang_links_only_include_live_public_translations( + self, translated_pages_mock + ): + request = self.factory.get("/en/contact/") + current_page = SimpleNamespace( + translation_key="key", + locale=SimpleNamespace(language_code="en"), + url="/en/contact/", + ) + translated_pages_mock.return_value = { + "nl": SimpleNamespace(url="/contact/", locale=SimpleNamespace(language_code="nl")), + "en": SimpleNamespace(url="/en/contact/", locale=SimpleNamespace(language_code="en")), + } + + links = localized_navigation.page_hreflang_links( + {"request": request, "page": current_page} + ) + + self.assertEqual( + links, + [ + {"code": "nl", "url": "https://www.mandelblog.com/contact/"}, + {"code": "en", "url": "https://www.mandelblog.com/en/contact/"}, + {"code": "x-default", "url": "https://www.mandelblog.com/contact/"}, + ], + )