Skip to content

Commit e848d4b

Browse files
authored
Merge pull request #230 from qld-gov-au/QOLSVC-10243-funnelback-robots
[QOLSVC-10243] exclude dataset search results from bot indexing
2 parents e1c8846 + b352829 commit e848d4b

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

ckan/templates/base.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<meta charset="utf-8" />
2727
<meta name="csrf_field_name" content="{{ g.csrf_field_name }}" />
2828
<meta name="{{ g.csrf_field_name }}" content="{{ csrf_token() }}" />
29+
{# Search result pages shouldn't be indexed by bots. #}
30+
{% if has_search_args %}
31+
<meta name="robots" content="noindex, follow" />
32+
{% endif %}
2933

3034
{% block meta_generator %}<meta name="generator" content="ckan {{ h.ckan_version() }}" />{% endblock %}
3135
{% block meta_viewport %}<meta name="viewport" content="width=device-width, initial-scale=1.0">{% endblock %}

ckan/views/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def _get_search_details() -> dict[str, Any]:
213213
def search(package_type: str) -> str:
214214
extra_vars: dict[str, Any] = {}
215215

216+
extra_vars['has_search_args'] = True if request.args else False
216217
extra_vars['q'] = q = request.args.get('q', '')
217218

218219
extra_vars['query_error'] = False

ckan/views/group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def index(group_type: str, is_organization: bool) -> str:
130130

131131
extra_vars["q"] = q
132132
extra_vars["sort_by_selected"] = sort_by
133+
extra_vars['has_search_args'] = True if request.args else False
133134

134135
# pass user info to context as needed to view private datasets of
135136
# orgs correctly
@@ -388,7 +389,7 @@ def _get_group_dict(id: str, is_organization: bool) -> dict[str, Any]:
388389
def read(group_type: str,
389390
is_organization: bool,
390391
id: Optional[str] = None) -> Union[str, Response]:
391-
extra_vars = {}
392+
extra_vars: dict[str, Any] = {u'has_search_args': True if request.args else False}
392393
context: Context = {
393394
u'user': current_user.name,
394395
u'schema': _db_to_form_schema(group_type=group_type),

0 commit comments

Comments
 (0)