Skip to content

Commit

Permalink
Merge pull request Hexlet#365 from jespy666/add-canonical-url
Browse files Browse the repository at this point in the history
[Hexlet#364] Add canonical url
  • Loading branch information
sgmdlt authored and DREU007 committed Nov 26, 2023
2 parents c5dab57 + ea077b6 commit a5530f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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
7 changes: 6 additions & 1 deletion templates/components/issue_tags_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
{% for label in all_contribution_labels %}
<a href="{% url 'contributors:open_issues' %}{% get_contribution_label_query_string label|lower %}"
class="text-decoration-none">
<span class="badge bg-primary {% if label not in contribution_labels %} bg-secondary {% endif %}">{{ label }}</span>
<span class="badge {% if label not in contribution_labels %}bg-success{% else %}bg-secondary{% endif %}">{{ label }}</span>
</a>
{% endfor %}
</div>
<div>
<a href="{% url 'contributors:open_issues' %}">
<span class="btn btn-outline-danger">Reset</span>
</a>
</div>

0 comments on commit a5530f6

Please sign in to comment.