From a8e62a564dffe56f761c86e77f778134fd1b63ca Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 14 Nov 2017 17:25:32 +0000 Subject: [PATCH] Add meta description tag to homepage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Google tries to auto-generate a snippet of a site’s content to show in search results. Currently it’s not doing a great job of this for Notify. There’s a chance that if we give it better content in the site’s meta description then it will use that instead. Worth a go… The content is adapted from the blue box on the product page. It’s 145 characters, which is within the 160 characters recommended[1] It matches the content in the page, and contains words that users are likely to be searching for (GOV.UK Notify, emails, text messages). It’s only on the homepage, because it shouldn’t be duplicated across multiple pages. https://yoast.com/meta-descriptions/ --- app/templates/admin_template.html | 2 ++ app/templates/views/signedout.html | 4 ++++ tests/app/main/views/test_index.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index 1c8acd287..2789bfec9 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -18,6 +18,8 @@ + {% block meta %} + {% endblock %} {% endblock %} {% block page_title %} diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 64776c5e6..37954b1b2 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -1,5 +1,9 @@ {% extends "fullwidth_template.html" %} +{% block meta %} + +{% endblock %} + {% block page_title %} GOV.UK Notify {% endblock %} diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 2e46706e9..1f6e46b33 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -1,7 +1,21 @@ import pytest +from bs4 import BeautifulSoup from flask import url_for +def test_non_logged_in_user_can_see_homepage( + client, +): + response = client.get(url_for('main.index')) + assert response.status_code == 200 + + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + + assert page.select_one('meta[name=description]')['content'].startswith( + 'GOV.UK Notify lets your send emails and text messages' + ) + + def test_logged_in_user_redirects_to_choose_service( logged_in_client, api_user_active, @@ -27,6 +41,10 @@ def test_static_pages( response = client.get(url_for('main.{}'.format(view))) assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + + assert not page.select_one('meta[name=description]') + @pytest.mark.parametrize('view, expected_anchor', [ ('delivery_and_failure', 'messagedeliveryandfailure'),