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: vocab description, site name, type, canonical URL #1657

Merged
merged 7 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion src/model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getRequestUri()
*/
public function getLangUrl($newlang=null)
{
$script_name = str_replace('/index.php', '', $this->getServerConstant('SCRIPT_NAME'));
$script_name = str_replace('/src/index.php', '', $this->getServerConstant('SCRIPT_NAME'));
$langurl = substr(str_replace($script_name, '', strval($this->getServerConstant('REQUEST_URI'))), 1);
if ($newlang !== null) {
$langurl = preg_replace("#^(.*/)?{$this->lang}/#", "$1{$newlang}/", $langurl);
Expand Down
9 changes: 9 additions & 0 deletions src/model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ public function getTitle($lang = null)
return $this->getLiteral('dc:title', false, $lang);
}

/**
* Returns the human readable vocabulary description.
* @return string the description of the vocabulary
*/
public function getDescription($lang = null)
{
return $this->getLiteral('dc:description', false, $lang);
}

/**
* Returns the sorting strategy for notation codes set in the config.ttl
* config: either "lexical", "natural", or null if sorting by notations is
Expand Down
1 change: 1 addition & 0 deletions src/view/about.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% extends "base-template.twig" %}
{% block title %}{{ "About" | trans}} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ GlobalConfig.aboutDescription(request.lang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}

{% block content %}

Expand Down
9 changes: 7 additions & 2 deletions src/view/base-template.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html dir="ltr" lang="{{ request.lang }}">
<html dir="ltr" lang="{{ request.lang }}" prefix="og: https://ogp.me/ns#">
<head>
<base href="{{ BaseHref }}">
<link rel="shortcut icon" href="favicon.ico">
Expand All @@ -15,7 +15,12 @@
<meta name="description" content="{{ block('description') }}">
<meta property="og:description" content="{{ block('description') }}">
{% endif %}
<meta name="twitter:card" content="summary">
{% if block('url') is defined and block('url') is not empty %}
<link rel="canonical" href="{{ block('url') }}">
<meta property="og:url" content="{{ block('url') }}">
{% endif %}
<meta property="og:type" content="website">
<meta property="og:site_name" content="{{ GlobalConfig.serviceName }}">
<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">
<link href="resource/css/skosmos.css" media="screen, print" rel="stylesheet" type="text/css">
Expand Down
1 change: 1 addition & 0 deletions src/view/concept.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% set pageType = 'concept' %}
{% extends "base-template.twig" %}
{% block title %}{{ concept.label }} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ concept.uri|link_url(vocab,request.lang,'page',request.contentLang) }}{% endblock %}

{% block content %}
{% include "sidebar.inc" %}
Expand Down
1 change: 1 addition & 0 deletions src/view/error.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% set pageType = 'error' %}
{% extends "base-template.twig" %}
{% block title %}{{ "Error"| trans }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block content %}
{% set pageError = request.vocabid != '' and request.page == 'page' %}
{% if pageError %}
Expand Down
1 change: 1 addition & 0 deletions src/view/feedback.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

{% block content %}

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

{% block content %}
<div class="col-md-7">
Expand Down
2 changes: 2 additions & 0 deletions src/view/vocab-home.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% set pageType = 'vocab-home' %}
{% extends "base-template.twig" %}
{% block title %}{{ vocab.title(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ vocab.config.description(request.contentLang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}


{% block content %}
Expand Down
2 changes: 2 additions & 0 deletions src/view/vocab-search.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% set pageType = 'vocab-search' %}
{% extends "base-template.twig" %}
{% block title %}'{{ term }}' - {{ vocab.shortName(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}

{% block content %}
<main class="searchpage py-5" id="main-container" >
<div class="container">
Expand Down
14 changes: 7 additions & 7 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testGetVersion()
*/
public function testGetLangUrlNoParamRoot()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/en/');
$langurl = $this->request->getLangUrl();
$this->assertEquals("en/", $langurl);
Expand All @@ -190,7 +190,7 @@ public function testGetLangUrlNoParamRoot()
*/
public function testGetLangUrlNoParamVocab()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/');
$langurl = $this->request->getLangUrl();
$this->assertEquals("myvocab/en/", $langurl);
Expand All @@ -201,7 +201,7 @@ public function testGetLangUrlNoParamVocab()
*/
public function testGetLangUrlNoParamVocabIndex()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/index');
$langurl = $this->request->getLangUrl();
$this->assertEquals("myvocab/en/index", $langurl);
Expand All @@ -212,7 +212,7 @@ public function testGetLangUrlNoParamVocabIndex()
*/
public function testGetLangUrlNewLangRoot()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/en/');
$this->request->setLang('en');
$langurl = $this->request->getLangUrl("sv");
Expand All @@ -224,7 +224,7 @@ public function testGetLangUrlNewLangRoot()
*/
public function testGetLangUrlNewLangVocab()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/');
$this->request->setLang('en');
$langurl = $this->request->getLangUrl("sv");
Expand All @@ -236,7 +236,7 @@ public function testGetLangUrlNewLangVocab()
*/
public function testGetLangUrlNewLangVocabIndex()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/index');
$this->request->setLang('en');
$langurl = $this->request->getLangUrl("sv");
Expand All @@ -248,7 +248,7 @@ public function testGetLangUrlNewLangVocabIndex()
*/
public function testGetLangUrlSanitizeSpecialChars()
{
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php');
$this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php');
$this->request->setServerConstant('REQUEST_URI', '/Skosmos/http://example.com');
$this->request->setLang('en');
$langurl = $this->request->getLangUrl();
Expand Down
9 changes: 9 additions & 0 deletions tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ public function testGetTitle()
$this->assertEquals('Test ontology', $vocab->getConfig()->getTitle('en'));
}

/**
* @covers VocabularyConfig::getDescription
*/
public function testGetDesctiption()
{
$vocab = $this->model->getVocabulary('test');
$this->assertEquals('Description of Test ontology', $vocab->getConfig()->getDescription('en'));
}

/**
* @covers VocabularyConfig::getShowDeprecatedChanges
* @covers VocabularyConfig::getBoolean
Expand Down
2 changes: 1 addition & 1 deletion tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function testGetInfo()
{
$vocab = $this->model->getVocabulary('test');
$info = $vocab->getInfo();
$this->assertEquals(array("dc:title" => array('Test ontology'), 'dc:modified' => array('Wednesday, October 1, 2014 16:29:03'), "rdf:type" => array('http://www.w3.org/2004/02/skos/core#ConceptScheme' => 'http://www.w3.org/2004/02/skos/core#ConceptScheme'), "owl:versionInfo" => array('The latest and greatest version')), $info);
$this->assertEquals(array("dc:title" => array('Test ontology'), 'dc:modified' => array('Wednesday, October 1, 2014 16:29:03'), "rdf:type" => array('http://www.w3.org/2004/02/skos/core#ConceptScheme' => 'http://www.w3.org/2004/02/skos/core#ConceptScheme'), "owl:versionInfo" => array('The latest and greatest version'), "dc:description" => array('Description of Test ontology')), $info);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/cypress/template/about.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ describe('About page', () => {
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 site name metadata', () => {
// go to the Skosmos about page
cy.visit('/en/about')

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
// go to the Skosmos about page
cy.visit('/en/about')

const expectedUrl = Cypress.config('baseUrl') + 'en/about'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Contains version number information', () => {
// go to the Skosmos about page
cy.visit('/en/about')
Expand Down
24 changes: 24 additions & 0 deletions tests/cypress/template/concept.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ describe('Concept 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 site name metadata', () => {
cy.visit('/yso/en/page/p1265') // go to "archaeology" concept page

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata (short URL)', () => {
cy.visit('/yso/en/page/p1265') // go to "archaeology" concept page

const expectedUrl = Cypress.config('baseUrl') + 'yso/en/page/p1265'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Contains canonical URL metadata (long URL)', () => {
// go to "archaeology" concept page using long URL based on URI
cy.visit('/yso/en/page/?uri=http%3A%2F%2Fwww.yso.fi%2Fonto%2Fyso%2Fp1265')

const expectedUrl = Cypress.config('baseUrl') + 'yso/en/page/p1265'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it("doesn't contain breadcrumbs for top concepts", () => {
cy.visit('/yso/en/page/p4762') // go to "objects" concept page

Expand Down
17 changes: 17 additions & 0 deletions tests/cypress/template/error.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ describe('Error 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 site name metadata', () => {
// go to a non-existing page
cy.visit('/404', {failOnStatusCode: false})

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
// go to a non-existing page
cy.visit('/404', {failOnStatusCode: false})

const expectedUrl = Cypress.config('baseUrl') + '404/'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Contains 404 error code', () => {
// check that HTTP code is 404 when accessing a non-existing page
cy.request({url: '/404', failOnStatusCode: false}).its('status').should('equal', 404)
Expand Down
34 changes: 34 additions & 0 deletions tests/cypress/template/feedback.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ describe('Feedback page', () => {
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 site name metadata', () => {
// go to the general feedback page
cy.visit('/en/feedback')

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
// go to the general feedback page
cy.visit('/en/feedback')

const expectedUrl = Cypress.config('baseUrl') + 'en/feedback'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Sends feedback', () => {
// go to the general feedback page
cy.visit('/en/feedback')
Expand Down Expand Up @@ -75,6 +92,23 @@ describe('Vocab feedback page', () => {
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 site name metadata', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')

const expectedUrl = Cypress.config('baseUrl') + 'test/en/feedback'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Displays correct vocab option', () => {
// go to test vocab feedback page
cy.visit('/test/en/feedback')
Expand Down
17 changes: 17 additions & 0 deletions tests/cypress/template/landing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ describe('Landing page', () => {
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 site name metadata', () => {
// go to the Skosmos front page
cy.visit('/')

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
// go to the Skosmos front page
cy.visit('/')

const expectedUrl = Cypress.config('baseUrl') + 'en/'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('links to vocabulary home', () => {
// go to the Skosmos front page
cy.visit('/')
Expand Down
24 changes: 24 additions & 0 deletions tests/cypress/template/vocab-home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ describe('Vocabulary home 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', () => {
cy.visit('/test/en') // go to the "Test ontology" home page

const expectedDescription = 'Description of Test ontology'

// 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 site name metadata', () => {
cy.visit('/test/en') // go to the "Test ontology" home page

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
cy.visit('/test/en') // go to the "Test ontology" home page

const expectedUrl = Cypress.config('baseUrl') + 'test/en/'
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('contains vocabulary title', () => {
cy.visit('/test/en') // go to the "Test ontology" home page

Expand Down
15 changes: 15 additions & 0 deletions tests/cypress/template/vocab-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ describe('Vocabulary search 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 site name metadata', () => {
cy.visit(`/${vocab}/en/search?clang=en&q=${term}`)

const expectedSiteName = 'Skosmos being tested'
// check that the page has site name metadata
cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName);
})
it('Contains canonical URL metadata', () => {
cy.visit(`/${vocab}/en/search?clang=en&q=${term}`)

const expectedUrl = Cypress.config('baseUrl') + `${vocab}/en/search?clang=en&q=${term}`
// check that the page has canonical URL metadata
cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl);
cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl);
})
it('Contains correct amount of search results ', () => {
const count = 1;
const searchCountTitle = `${count} results for \'${term}\'`;
Expand Down
Loading
Loading