Skip to content

Commit

Permalink
Older versions of the standard should not be indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Oct 29, 2024
1 parent c0483b5 commit 0ff3050
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions iati/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,5 @@
}

COMPRESS_OFFLINE = True

IATI_STANDARD_LATEST_VERSION = "2.03"
3 changes: 3 additions & 0 deletions iati/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% endblock %}

{% block html_header_seo %}
{% endblock %}
</head>

<body class="body--message {% block body_class %}{% endblock %}" id="{% block body_id %}{% endblock %}">
Expand Down
29 changes: 28 additions & 1 deletion iati_standard/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Model definitions for the iati_standard app."""

import os
import re
from bs4 import BeautifulSoup
from datetime import datetime

from django import forms
from django.conf import settings
from django.db.models import JSONField
from django.db import models
from django.utils.functional import cached_property
Expand Down Expand Up @@ -397,10 +399,35 @@ def save(self, *args, **kwargs):


class ActivityStandardPage(AbstractGithubPage):
"""A model for the Activity Standard Page, an IATI reference page."""
"""A model for the Activity Standard Page, an IATI reference page.
Used for Standard reference pages like /en/iati-standard/202/
And guidance developer pages like /en/guidance/developer/
"""

template = 'iati_standard/activity_standard_page.html'

def is_older_version_of_standard(self):
"""Is it an older version of the standard? Return Boolean."""
url = self.get_url()
if re.match(r"^\/\w+\/iati-standard\/\d", url):
regex = r"^\/\w+\/iati-standard\/" + settings.IATI_STANDARD_LATEST_VERSION.replace(".", "") + r"\/"
if not re.match(regex, url):
return True
return False

def get_sitemap_urls(self, request=None):
"""If it's an older version of the standard, we don't want it indexed."""
if self.is_older_version_of_standard():
return []
else:
return [
{
'location': self.get_full_url(request),
'lastmod': (self.last_published_at or self.latest_revision_created_at),
}
]


class StandardGuidancePage(AbstractGithubPage):
"""A model for the Standard Guidance Page, an IATI reference page."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
</style>
{% endblock %}

{% block html_header_seo %}
{% if page.is_older_version_of_standard %}<meta name="robots" content="noindex, nofollow">{% endif %}
{% endblock %}

{% block content %}
{% get_current_language as LANGUAGE_CODE %}
<div class="hero hero--minor">
Expand Down

0 comments on commit 0ff3050

Please sign in to comment.