Skip to content

Commit

Permalink
Ensure we only use x-default on appropriate pages (#15526)
Browse files Browse the repository at this point in the history
* Remove hreflang="x-default" link from credits FAQ page

* Only show hreflang="x-default" if it's on the homepage for a locale

(Separately, the nonlocale root page at / also serves hreflang="x-default"
already, and this change does not affect that because it's got its own
template which does not use the canonical-url.html partial)
  • Loading branch information
stevejalim authored Nov 20, 2024
1 parent f445fb6 commit 696d846
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bedrock/base/templates/includes/canonical-url.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{%- set available_languages = get_locale_options(request, translations) -%}

<link rel="canonical" href="{{ settings.CANONICAL_URL + '/' + LANG + canonical_path }}">
<link rel="alternate" hreflang="x-default" href="{{ settings.CANONICAL_URL }}{{ canonical_path }}">
{% if is_homepage %}<link rel="alternate" hreflang="x-default" href="{{ settings.CANONICAL_URL }}{{ canonical_path }}">{% endif %}
{% if available_languages -%}
{%- for code, label in available_languages|dictsort -%}
{%- set alt_url = alternate_url(canonical_path, code) -%}
Expand Down
1 change: 0 additions & 1 deletion bedrock/mozorg/templates/mozorg/credits-faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

{% block canonical_urls %}
<link rel="canonical" href="{{ canonical_url }}">
<link rel="alternate" hreflang="x-default" href="{{ canonical_url }}">
{% endblock %}

{% block page_og_url %}{{ canonical_url }}{% endblock %}
Expand Down
5 changes: 5 additions & 0 deletions bedrock/mozorg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class HomeView(L10nTemplateView):

ftl_files_map = {old_template_name: ["mozorg/home"], template_name: ["mozorg/home-new"]}

def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx.update({"is_homepage": True})
return ctx

def get_template_names(self):
experience = self.request.GET.get("xv", None)

Expand Down

0 comments on commit 696d846

Please sign in to comment.