Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#364] Add canonical url #365

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions contributors/templatetags/contrib_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ def prepare_contribution_labels_param_value(labels_param): # noqa: WPS430
'contribution_labels',
prepare_contribution_labels_param_value,
)


@register.simple_tag(takes_context=True)
def get_canonical_url(context):
"""Get canonical url from request."""
request = context.get('request')
if request:
return request.build_absolute_uri(request.path)
return ''
1 change: 1 addition & 0 deletions contributors/views/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['all_labels'] = all_labels
context['labels'] = labels

return context
4 changes: 3 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n static %}
{% load i18n static contrib_extras %}
{% get_current_language as LANGUAGE_CODE %}
<!doctype html>
<html lang="{{ LANGUAGE_CODE }}" class="h-100">
Expand All @@ -22,6 +22,8 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="icon" type="image/png" href="{% static 'images/favicon.png' %}">
{% get_canonical_url as canonical_url %}
<link rel="canonical" href="{{ canonical_url }}">
<script src="{% url 'javascript_catalog' %}"></script>
{% block head_scripts %}{% endblock %}
{% if GTM_ID %}
Expand Down
Loading