Skip to content

Commit

Permalink
mod_seo: add all available hreflang and x-default links to head. (#3066)
Browse files Browse the repository at this point in the history
See also #3006
  • Loading branch information
mworrell committed Jul 22, 2022
1 parent 35d4d15 commit 97b98e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 6 additions & 4 deletions modules/mod_seo/templates/_html_head_seo.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% if id %}
<link rel="shortlink" href="{% block shortlink %}{% url id id=id use_absolute_url %}{% endblock %}" />
<link rel="canonical" href="{% block canonical %}{{ m.rsc[id].page_url_abs }}{% endblock %}" />
{% if id and id.is_a.query and q.page %}
<link rel="canonical" href="{% block canonical %}{{ m.rsc[id].page_url_abs }}{% endblock %}?page={{ q.page|escape }}" />
<link rel="shortlink" href="{% block shortlink %}{% url id id=id use_absolute_url %}{% endblock %}" />
{% elseif id %}
<link rel="canonical" href="{% block canonical %}{{ m.rsc[id].page_url_abs }}{% endblock %}" />
<link rel="shortlink" href="{% block shortlink %}{% url id id=id use_absolute_url %}{% endblock %}" />
{% endif %}

{% if m.config.seo.noindex.value or noindex %}
<meta name="robots" content="noindex,nofollow" />
{% elseif id and id.language and m.modules.active.mod_translation and not z_language|member:id.language %}
Expand Down
2 changes: 2 additions & 0 deletions modules/mod_translation/mod_translation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ observe_url_rewrite(#url_rewrite{args=Args}, Url, Context) ->
case z_context:language(Context) of
undefined ->
Url;
'x-default' ->
Url;
Language ->
case lists:keyfind(z_language, 1, Args) of
false ->
Expand Down
18 changes: 15 additions & 3 deletions modules/mod_translation/templates/_html_head_translation.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
{% if id and id.language %}{% for code in id.language %}{% if z_language != code %}
<link rel="alternate" hreflang="{{ code }}" href="{{ m.rsc[id].page_url_abs with z_language = code }}" title="{{ m.rsc[id].title with z_language = code }}" />
{% endif %}{% endfor %}{% endif %}
{% with m.config.mod_translation.rewrite_url.value|default_if_none:1 as rewrite_url %}
{% if id and id.is_a.query and q.page %}
{% if rewrite_url %}{% for code in id.language %}
<link rel="alternate" hreflang="{{ code }}" href="{{ m.rsc[id].page_url_abs with z_language = code }}?page={{ q.page|escape }}" title="{{ m.rsc[id].title with z_language = code }}">
{% endfor %}{% endif %}
<link rel="alternate" hreflang="x-default" href="{{ m.rsc[id].page_url_abs with z_language = `x-default` }}?page={{ q.page|escape }}" title="{{ m.rsc[id].title with z_language = `x-default` }}">
{% elseif id and id.language %}
{% if rewrite_url %}{% for code in id.language %}
<link rel="alternate" hreflang="{{ code }}" href="{{ m.rsc[id].page_url_abs with z_language = code }}" title="{{ m.rsc[id].title with z_language = code }}">
{% endfor %}{% endif %}
<link rel="alternate" hreflang="x-default" href="{{ m.rsc[id].page_url_abs with z_language = `x-default` }}" title="{{ m.rsc[id].title with z_language = `x-default` }}">
{% elseif id.exists %}
<link rel="alternate" hreflang="x-default" href="{{ m.rsc[id].page_url_abs with z_language = `x-default` }}" title="{{ m.rsc[id].title with z_language = `x-default` }}">
{% endif %}
{% endwith %}

0 comments on commit 97b98e8

Please sign in to comment.