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: long title on landing page (skosmos:serviceNameLong configuration setting) #1644

Merged
merged 4 commits into from
Aug 14, 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
10 changes: 6 additions & 4 deletions src/model/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ protected function getLiteral($property, $default=null, $lang=null)
return $literal->getValue();
}

// not found with selected language, try any language
$literal = $this->getResource()->getLiteral($property);
if ($literal) {
return $literal->getValue();
// not found with selected language, try to find one without a language tag
foreach ($this->getResource()->allLiterals($property) as $literal) {
if ($literal->getLang() === null) {
return $literal->getValue();
}
}

// not found, return the default value
return $default;
}

Expand Down
16 changes: 16 additions & 0 deletions src/model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ public function getServiceName()
return $this->getLiteral('skosmos:serviceName', 'Skosmos');
}

/**
* Returns the long version of the service name in the requested language.
* @return string the long name of the service
*/
public function getServiceNameLong($lang)
{
$val = $this->getLiteral('skosmos:serviceNameLong', false, $lang);

if ($val === false) {
// fall back to short service name if not configured
return $this->getServiceName();
}

return $val;
}

/**
* @return string
*/
Expand Down
1 change: 0 additions & 1 deletion src/view/base-template.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<meta name="generator" content="Skosmos {{ request.version }}">
<meta name="title" content="{{ block('title') }}">
<meta property="og:title" content="{{ block('title') }}">
<meta name="twitter:title" content="{{ block('title') }}">
<meta name="twitter:card" content="summary">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.x.com/en/docs/twitter-for-websites/cards/overview/markup#overview-of-all-twitter-card-tags

Now that we're getting rid of twitter:title in favour of og:title, we could also change twitter:card to og:type. I reckon the domain of og:type fits skosmos pages better than the domain of twitter:card.

<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
1 change: 1 addition & 0 deletions src/view/landing.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% set pageType = 'landing' %}
{% extends "base-template.twig" %}
{% block title %}{{ GlobalConfig.serviceNameLong(request.lang) }}{% endblock %}

{% block content %}
<div class="col-md-7">
Expand Down
15 changes: 15 additions & 0 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ public function testGetServiceName()
$this->assertEquals("Skosmos being tested", $this->config->getServiceName());
}

public function testGetServiceNameLongEn()
{
$this->assertEquals("Skosmos being tested, long title", $this->config->getServiceNameLong('en'));
}

public function testGetServiceNameLongNoLanguageFallback()
{
$this->assertEquals("Skosmos-long", $this->config->getServiceNameLong('fr'));
}

public function testGetServiceNameLongNotSetFallback()
{
$this->assertEquals("Skosmos", $this->configWithDefaults->getServiceNameLong('en'));
}

public function testGetBaseHref()
{
$this->assertEquals("http://tests.localhost/Skosmos/", $this->configWithBaseHref->getBaseHref());
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/template/about.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('About page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains version number information', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/template/concept.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ describe('Concept page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it("doesn't contain breadcrumbs for top concepts", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/template/error.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('Error page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains 404 error code', () => {
Expand Down
2 changes: 0 additions & 2 deletions tests/cypress/template/feedback.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('Feedback page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Sends feedback', () => {
Expand Down Expand Up @@ -56,7 +55,6 @@ describe('Vocab feedback page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Displays correct vocab option', () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/cypress/template/landing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ describe('Landing page', () => {
// go to the Skosmos front page
cy.visit('/')

const expectedTitle = 'Skosmos being tested'
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('links to vocabulary home', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/template/vocab-home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('Vocabulary home page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('contains vocabulary title', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/template/vocab-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('Vocabulary search page', () => {
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[name="twitter:title"]').should('have.attr', 'content', expectedTitle);
cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle);
})
it('Contains correct amount of search results ', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
skosmos:httpTimeout 2 ;
# customize the service name
skosmos:serviceName "Skosmos being tested" ;
skosmos:serviceNameLong "Skosmos being tested, long title"@en, "Skosmos-long" ;
# 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