Use meta tag to tell search engines not to index

Google’s documentation says:

> robots.txt is not a mechanism for keeping a web page out of Google. To
> keep a web page out of Google, you should use noindex directives

A noindex directive means adding the following meta tag to pages that
shouldn’t be indexed:
```html
<meta name="robots" content="noindex" />
```

It’s also possible to set the directive as a HTTP header, but this seems
trickier to achieve on a per-view basis in Flask.

I’ve implemented this as a decorator so it can quickly be added to any
other pages that we decide shouldn’t appear in search results.
This commit is contained in:
Chris Hill-Scott
2020-05-26 17:39:25 +01:00
parent b98f4561fa
commit 92ffe3a78c
7 changed files with 45 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ import pyexcel
import pyexcel_xlsx
import pytz
from dateutil import parser
from flask import abort, current_app, redirect, request, session, url_for
from flask import abort, current_app, g, redirect, request, session, url_for
from flask_login import current_user, login_required
from notifications_utils.field import Field
from notifications_utils.formatters import (
@@ -767,3 +767,11 @@ def is_less_than_90_days_ago(date_from_db):
return (datetime.utcnow() - datetime.strptime(
date_from_db, "%Y-%m-%dT%H:%M:%S.%fZ"
)).days < 90
def hide_from_search_engines(f):
@wraps(f)
def decorated_function(*args, **kwargs):
g.hide_from_search_engines = True
return f(*args, **kwargs)
return decorated_function