Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEO: descriptions on landing, about and feedback pages #1647

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,33 @@ public function getServiceNameLong($lang)
return $val;
}

/**
* Returns the service description in the requested language.
* @return string the description of the service
*/
public function getServiceDescription($lang)
{
return $this->getLiteral('skosmos:serviceDescription', null, $lang);
}

/**
* Returns the feedback page description in the requested language.
* @return string the description of the feedback page
*/
public function getFeedbackDescription($lang)
{
return $this->getLiteral('skosmos:feedbackDescription', null, $lang);
}

/**
* Returns the about page description in the requested language.
* @return string the description of the about page
*/
public function getAboutDescription($lang)
{
return $this->getLiteral('skosmos:aboutDescription', null, $lang);
}

/**
* @return string
*/
Expand Down
2 changes: 2 additions & 0 deletions src/view/about.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% set pageType = 'about' %}
{% extends "base-template.twig" %}
{% block title %}{{ "About" | trans}} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ GlobalConfig.aboutDescription(request.lang) }}{% endblock %}

{% block content %}

<div class="container">
Expand Down
4 changes: 4 additions & 0 deletions src/view/base-template.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<meta name="generator" content="Skosmos {{ request.version }}">
<meta name="title" content="{{ block('title') }}">
<meta property="og:title" content="{{ block('title') }}">
{% if block('description') is defined and block('description') is not empty %}
<meta name="description" content="{{ block('description') }}">
<meta property="og:description" content="{{ block('description') }}">
{% endif %}
<meta name="twitter:card" content="summary">
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" media="screen, print" rel="stylesheet" type="text/css">
<link href="resource/css/fonts.css" media="screen, print" rel="stylesheet" type="text/css">
Expand Down
4 changes: 3 additions & 1 deletion src/view/feedback.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% set pageType = 'feedback' %}
{% extends "base-template.twig" %}

{% block title %}{{ "Feedback"|trans }} - {{GlobalConfig.serviceName}}{% endblock %}
{% block title %}{{ "Feedback"|trans }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ GlobalConfig.feedbackDescription(request.lang) }}{% endblock %}

{% block content %}

{% if feedback_sent %}
Expand Down
1 change: 1 addition & 0 deletions src/view/landing.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% set pageType = 'landing' %}
{% extends "base-template.twig" %}
{% block title %}{{ GlobalConfig.serviceNameLong(request.lang) }}{% endblock %}
{% block description %}{{ GlobalConfig.serviceDescription(request.lang) }}{% endblock %}

{% block content %}
<div class="col-md-7">
Expand Down
30 changes: 30 additions & 0 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ public function testGetServiceNameLongNotSetFallback()
$this->assertEquals("Skosmos", $this->configWithDefaults->getServiceNameLong('en'));
}

public function testGetServiceDescription()
{
$this->assertEquals("Description of Skosmos being tested", $this->config->getServiceDescription('en'));
}

public function testGetServiceDescriptionNotInLanguage()
{
$this->assertNull($this->config->getServiceDescription('fr'));
}

public function testGetFeedbackDescription()
{
$this->assertEquals("Feedback page for Skosmos being tested", $this->config->getFeedbackDescription('en'));
}

public function testGetFeedbackDescriptionNotInLanguage()
{
$this->assertNull($this->config->getFeedbackDescription('fr'));
}

public function testGetAboutDescription()
{
$this->assertEquals("About page for Skosmos being tested", $this->config->getAboutDescription('en'));
}

public function testGetAboutDescriptionNotInLanguage()
{
$this->assertNull($this->config->getAboutDescription('fr'));
}

public function testGetBaseHref()
{
$this->assertEquals("http://tests.localhost/Skosmos/", $this->configWithBaseHref->getBaseHref());
Expand Down
11 changes: 10 additions & 1 deletion tests/cypress/template/about.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('About page', () => {
it('Contains title and title metadata', () => {
it('Contains title metadata', () => {
// go to the Skosmos about page
cy.visit('/en/about')

Expand All @@ -10,6 +10,15 @@ describe('About page', () => {
cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains description metadata', () => {
// go to the Skosmos about page
cy.visit('/en/about')

const expectedDescription = 'About page for Skosmos being tested'
// check that the page has description metadata
cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription);
cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription);
})
it('Contains version number information', () => {
// go to the Skosmos about page
cy.visit('/en/about')
Expand Down
22 changes: 20 additions & 2 deletions tests/cypress/template/feedback.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Feedback page', () => {
it('Contains title and title metadata', () => {
it('Contains title metadata', () => {
// go to the general feedback page
cy.visit('/en/feedback')

Expand All @@ -10,6 +10,15 @@ describe('Feedback page', () => {
cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains description metadata', () => {
// go to the general feedback page
cy.visit('/en/feedback')

const expectedDescription = 'Feedback page for Skosmos being tested'
// check that the page has description metadata
cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription);
cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription);
})
it('Sends feedback', () => {
// go to the general feedback page
cy.visit('/en/feedback')
Expand Down Expand Up @@ -46,7 +55,7 @@ describe('Feedback page', () => {
})

describe('Vocab feedback page', () => {
it('Contains title and title metadata', () => {
it('Contains title metadata', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')

Expand All @@ -57,6 +66,15 @@ describe('Vocab feedback page', () => {
cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains description metadata', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')

const expectedDescription = 'Feedback page for Skosmos being tested'
// check that the page has description metadata
cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription);
cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription);
})
it('Displays correct vocab option', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')
Expand Down
13 changes: 12 additions & 1 deletion tests/cypress/template/landing.cy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
describe('Landing page', () => {
it('Contains title and title metadata', () => {
it('Contains title metadata', () => {
// go to the Skosmos front page
cy.visit('/')

const expectedTitle = 'Skosmos being tested, long title'

// check that the page has a HTML title
cy.get('title').invoke('text').should('equal', expectedTitle)
// check that the page has title metadata
cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains description metadata', () => {
// go to the Skosmos front page
cy.visit('/')

const expectedDescription = 'Description of Skosmos being tested'

// check that the page has description metadata
cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription);
cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription);
})
it('links to vocabulary home', () => {
// go to the Skosmos front page
cy.visit('/')
Expand Down
3 changes: 3 additions & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
# customize the service name
skosmos:serviceName "Skosmos being tested" ;
skosmos:serviceNameLong "Skosmos being tested, long title"@en, "Skosmos-long" ;
skosmos:serviceDescription "Description of Skosmos being tested"@en ;
osma marked this conversation as resolved.
Show resolved Hide resolved
skosmos:feedbackDescription "Feedback page for Skosmos being tested"@en ;
skosmos:aboutDescription "About page for Skosmos being tested"@en ;
# customize the base element. Set this if the automatic base url detection doesn't work. For example setups behind a proxy.
#skosmos:baseHref "http://localhost/Skosmos/" ;
# interface languages available, and the corresponding system locales
Expand Down
Loading