Skip to content

Commit

Permalink
communities: Add noindex meta tags to unverified community pages
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba committed Dec 12, 2024
1 parent a11ff41 commit 16bce6b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
15 changes: 15 additions & 0 deletions site/zenodo_rdm/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

"""Filters to be used in the Jinja templates."""

from invenio_communities.proxies import current_communities
from invenio_rdm_records.proxies import current_rdm_records_service as records_service
from invenio_records.dictutils import dict_lookup

Expand Down Expand Up @@ -46,3 +47,17 @@ def is_verified_record(record):
return record.parent.is_verified
except Exception:
return False


def is_verified_community(community):
"""Return ``True`` if record is verified.
NOTE: This is not a good way to check in a Jinja template if a record is verified,
since it fetches again the record from the DB. We should include the verification
information in the template context.
"""
try:
comm = current_communities.service.record_cls.pid.resolve(community["id"])
return comm.is_verified
except Exception:
return False
3 changes: 2 additions & 1 deletion site/zenodo_rdm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from marshmallow import ValidationError

from .decorators import cached_unless_authenticated_or_flashes
from .filters import is_blr_related_record, is_verified_record
from .filters import is_blr_related_record, is_verified_community, is_verified_record
from .support.support import ZenodoSupport


Expand Down Expand Up @@ -91,5 +91,6 @@ def handle_validation_errors(e):
# Register template filters
blueprint.add_app_template_filter(is_blr_related_record)
blueprint.add_app_template_test(is_verified_record, name="verified_record")
blueprint.add_app_template_test(is_verified_community, name="verified_community")

return blueprint
30 changes: 30 additions & 0 deletions templates/semantic-ui/invenio_communities/details/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{# -*- coding: utf-8 -*-

This file is part of Zenodo.
Copyright (C) 2024 CERN.

Zenodo is a free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}

{% extends "invenio_communities/base.html" %}

{%- if community is not verified_community -%}
{% set meta_robot_tags = [
{
"name": "robots",
"content": "noindex, nofollow",
"data-reason": ("Community is not verified" if permissions.can_moderate),
}
] %}
{%- endif -%}

{%- block javascript %}
{{ super() }}
{{ webpack['invenio-communities-header.js'] }}
{%- endblock javascript %}

{%- block page_body %}
{% set community_menu_active = True %}
{% include "invenio_communities/details/header.html" %}
{%- endblock page_body %}

0 comments on commit 16bce6b

Please sign in to comment.