Skip to content

Commit

Permalink
SEO: add link rel=canonical and og:url metadata for all page types
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Aug 21, 2024
1 parent 9bdb894 commit 6284b25
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 0 deletions.
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.lang }}/about{% endblock %}

{% block content %}

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 @@ -15,6 +15,10 @@
<meta name="description" content="{{ block('description') }}">
<meta property="og:description" content="{{ block('description') }}">
{% endif %}
{% 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">
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 }}{% if request.vocab %}{{ request.vocab.id }}/{% endif %}{{ request.lang }}/feedback{% 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.lang }}/{% endblock %}

{% block content %}
<div class="col-md-7">
Expand Down
1 change: 1 addition & 0 deletions src/view/vocab-home.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% extends "base-template.twig" %}
{% block title %}{{ vocab.title(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ vocab.config.description(request.contentLang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ vocab.id }}/{{ request.lang }}/{% if request.contentLang != request.lang and request.contentLang != '' and request.contentLang in vocab.config.languages %}?clang={{ request.contentLang }}{% endif %}{% 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 }}{{ vocab.id }}/{{ request.lang }}/search?clang={{ request.contentLang}}&amp;q={{ term|url_encode }}{% endblock %}

{% block content %}
<main class="searchpage py-5" id="main-container" >
<div class="container">
Expand Down
9 changes: 9 additions & 0 deletions tests/cypress/template/about.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ describe('About page', () => {
// 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
17 changes: 17 additions & 0 deletions tests/cypress/template/concept.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ describe('Concept page', () => {
// 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
9 changes: 9 additions & 0 deletions tests/cypress/template/error.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ describe('Error page', () => {
// 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
18 changes: 18 additions & 0 deletions tests/cypress/template/feedback.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ describe('Feedback page', () => {
// 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 @@ -91,6 +100,15 @@ describe('Vocab feedback page', () => {
// 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
9 changes: 9 additions & 0 deletions tests/cypress/template/landing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ describe('Landing page', () => {
// 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
8 changes: 8 additions & 0 deletions tests/cypress/template/vocab-home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ describe('Vocabulary home page', () => {
// 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
8 changes: 8 additions & 0 deletions tests/cypress/template/vocab-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe('Vocabulary search page', () => {
// 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

0 comments on commit 6284b25

Please sign in to comment.