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 functionality backport for skosmos 2 #1666

Merged
merged 14 commits into from
Aug 23, 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
14 changes: 3 additions & 11 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,9 @@
$this->twig->addExtension(new Twig_Extensions_Extension_I18n());
// used for setting the base href for the relative urls
$this->twig->addGlobal("BaseHref", $this->getBaseHref());
// setting the service name string from the config.ttl
$this->twig->addGlobal("ServiceName", $this->model->getConfig()->getServiceName());

// setting the service custom css file from the config.ttl
if ($this->model->getConfig()->getCustomCss() !== null) {
$this->twig->addGlobal("ServiceCustomCss", $this->model->getConfig()->getCustomCss());
}
// used for displaying the ui language selection as a dropdown
if ($this->model->getConfig()->getUiLanguageDropdown() !== null) {
$this->twig->addGlobal("LanguageDropdown", $this->model->getConfig()->getUiLanguageDropdown());
}
// pass the GlobalConfig object to templates so they can access configuration
$this->twig->addGlobal("GlobalConfig", $this->model->getConfig());

// setting the list of properties to be displayed in the search results
$this->twig->addGlobal("PreferredProperties", array('skos:prefLabel', 'skos:narrower', 'skos:broader', 'skosmos:memberOf', 'skos:altLabel', 'skos:related'));
Expand Down Expand Up @@ -140,7 +132,7 @@
// set language parameters for gettext
$this->setLanguageProperties($request->getLang());
// load template
$template = $this->twig->loadTemplate('light.twig');
$template = $this->twig->loadTemplate('landing.twig');

Check warning on line 135 in controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

controller/WebController.php#L135

Added line #L135 was not covered by tests
// set template variables
$categoryLabel = $this->model->getClassificationLabel($request->getLang());
$sortedVocabs = $this->model->getVocabularyList(false, true);
Expand Down
11 changes: 7 additions & 4 deletions model/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,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
43 changes: 43 additions & 0 deletions model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,49 @@ 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;
}

/**
* 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
9 changes: 9 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,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
Binary file modified resource/translations/en/LC_MESSAGES/skosmos.mo
Binary file not shown.
Binary file modified resource/translations/fi/LC_MESSAGES/skosmos.mo
Binary file not shown.
Binary file modified resource/translations/se/LC_MESSAGES/skosmos.mo
Binary file not shown.
6 changes: 6 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -873,3 +873,9 @@ msgstr "Code that uniquely identifies a concept within a concept scheme."

msgid "Information"
msgstr "Information"

msgid "Error"
msgstr "Error"

msgid "Concept %term% in vocabulary %vocab%"
msgstr "Concept %term% in vocabulary %vocab%"
6 changes: 6 additions & 0 deletions resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,9 @@ msgstr "Tunniste, joka yksilöi käsitteen sanaston sisällä."

msgid "Information"
msgstr "Tietoja"

msgid "Error"
msgstr "Virhe"

msgid "Concept %term% in vocabulary %vocab%"
msgstr "Käsite %term% sanastossa %vocab%"
6 changes: 6 additions & 0 deletions resource/translations/skosmos_se.po
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,9 @@ msgstr "Dovddaldat, mii spesifisere doahpaga sátneráju siste. "

msgid "Information"
msgstr "Diehtu"

msgid "Error"
msgstr "Error"

msgid "Concept %term% in vocabulary %vocab%"
msgstr "Doaba %term% sátnerájus %vocab%"
6 changes: 6 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,9 @@ msgstr "Kod som unikt identifierar ett begrepp i en vokabulär."

msgid "Information"
msgstr "Information"

msgid "Error"
msgstr "Fel"

msgid "Concept %term% in vocabulary %vocab%"
msgstr "Begreppet %term% i vokabulären %vocab%"
Binary file modified resource/translations/sv/LC_MESSAGES/skosmos.mo
Binary file not shown.
45 changes: 45 additions & 0 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,51 @@ 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 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->config->getBaseHref());
Expand Down
9 changes: 9 additions & 0 deletions tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,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::showChangeList
* @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 @@ -204,7 +204,7 @@ public function testGetAlphabetIssue107() {
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
5 changes: 5 additions & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
skosmos:httpTimeout 8 ;
# 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 ;
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://tests.localhost/Skosmos/" ;
# interface languages available, and the corresponding system locales
Expand Down Expand Up @@ -72,6 +76,7 @@

:test a skosmos:Vocabulary, void:Dataset ;
dc:title "Test ontology"@en ;
dc:description "Description of Test ontology"@en ;
dc:subject :cat_science ;
dc:type mdrtype:ONTOLOGY ;
void:dataDump <http://skosmos.skos/dump/test/> ;
Expand Down
5 changes: 4 additions & 1 deletion view/about.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{% extends "light.twig" %}
{% block title %}{{ "About" | trans}} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{{ GlobalConfig.aboutDescription(request.lang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block sidebar %}{% endblock %}
{% block headernav %}{% endblock %}
{% block content %}
Expand All @@ -12,7 +15,7 @@
</div>
<div class="about-extra-info">
<div class="credits">
<p>{% if ServiceName != 'SERVICE_NAME' %}{{ ServiceName }}{% else %}Skosmos{% endif %} {% trans "layout designed by Hahmo" %}</p>
<p>{% if GlobalConfig.serviceName != 'SERVICE_NAME' %}{{ GlobalConfig.serviceName }}{% else %}Skosmos{% endif %} {% trans "layout designed by Hahmo" %}</p>
</div>
<div class="version">
{% set version = request.version %}
Expand Down
3 changes: 2 additions & 1 deletion view/alphabetical-index.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "light.twig" %}
{% block title %}: {{ vocab.shortName }}: {% trans "Alphabetical index" %}: {{ request.letter }}{% endblock %}
{% block title %}{% trans "Alphabetical index" %} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}

{% block content %}
{% include "vocab-shared.twig" %}
Expand Down
4 changes: 2 additions & 2 deletions view/changes.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "light.twig" %}
{% block title %}: {{ vocab.title(request.contentLang) }}{% endblock %}

{% block title %}{% if vocab.config.showDeprecatedChanges %}{% trans "Changes-and-deprecations-nav" %}{% else %}{% trans "Changes-nav" %}{% endif %} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block sidebar %}
<div class="sidebar-buttons">
<h2 class="sr-only">{% trans "Sidebar listing: list and traverse vocabulary contents by a criterion" %}</h2>
Expand Down
5 changes: 3 additions & 2 deletions view/concept-info.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

{% extends "light.twig" %}
{% set concept_label = '' %}{% for concept in search_results %}{% set concept_label = concept.label %}{% endfor %}
{% block title %}: {{ vocab.shortName }}{% if search_results|length == 1 %}: {{ concept_label }}{% endif %}
{% endblock %}
{% block title %}{{ concept_label }} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block description %}{% set term = concept_label %}{% set vocabObj = vocab %}{% set vocab = vocab.title(request.contentLang) %}{% trans %}Concept {{ term }} in vocabulary {{ vocab }}{% endtrans %}{% set vocab = vocabObj %}{% endblock %}
Copy link
Contributor

Choose a reason for hiding this comment

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

The minor quip is that we have only the translation strings for "Concept X" in different languages, whereas it look a bit weird in cases where the data is instances or classification:

  • Skosmos2/ykl/en/page/2
    • "Concept RELIGION in vocabulary PLC - Finnish Public Libraries Classification System"
    • Could be currently generated as "YKL Class RELIGION ..."
  • Skosmos2/finaf/en/page/000179638
    • "Concept A. Aallon Rytmiorkesteri in vocabulary KANTO - Kansalliset toimijatiedot"
    • Could be currently merely generated as "Yhteisö A. Aallon Rytmiorkesteri ..." as there's no translation for the concept type in english in the data

One way would be to omit the word "Concept" but it's a minor thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! This was part of the speccing done earlier. I guess we didn't consider classifications back then.

{% block url %}{{ BaseHref }}{{ search_results[0].uri|link_url(vocab,request.lang,'page',request.contentLang) }}{% endblock %}
{% block content %}
{% include "concept-shared.twig" %}
{% endblock %}
3 changes: 2 additions & 1 deletion view/error-page.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "light.twig" %}
{% block title %}: Error page{% endblock %}
{% block title %}{{ "Error"| trans }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block error %}
{% spaceless %}
{% set pageError = request.vocabid != '' and request.page == 'page' %}
Expand Down
4 changes: 3 additions & 1 deletion view/feedback.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends "light.twig" %}

{% block title %}: {% trans "Feedback" %}{% endblock %}
{% block title %}{{ "Feedback"|trans }} - {{GlobalConfig.serviceName}}{% endblock %}
{% block description %}{{ GlobalConfig.feedbackDescription(request.lang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block sidebar %}{% endblock %}
{% block headernav %}{% endblock %}
{% block content %}
Expand Down
3 changes: 2 additions & 1 deletion view/group-contents.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends "light.twig" %}

{% set group_label = '' %}{% for group in search_results %}{% set group_label = group.label %}{% endfor %}
{% block title %}: {{ vocab.config.shortName }}: {{ group_label }}{% endblock %}
{% block title %}{{ group_label }} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}

{% block sidebar %}
<div class="sidebar-buttons">
Expand Down
4 changes: 2 additions & 2 deletions view/group-index.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "light.twig" %}

{% block title %}: {{ vocab.shortName }}: {% trans "Group index" %}{% endblock %}

{% block title %}{% trans "Group index" %} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
{% block sidebar %}
<div class="sidebar-buttons">
<h2 class="sr-only">{% trans "Sidebar listing: list and traverse vocabulary contents by a criterion" %}</h2>
Expand Down
3 changes: 3 additions & 0 deletions view/landing.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "light.twig" %}
{% block description %}{{ GlobalConfig.serviceDescription(request.lang) }}{% endblock %}
{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %}
26 changes: 21 additions & 5 deletions view/light.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<!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">
{% include 'meta.twig' %}
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="format-detection" content="telephone=no">
<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 %}
{% 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="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" media="screen, print" rel="stylesheet" type="text/css">
<link href="vendor/vakata/jstree/dist/themes/default/style.min.css" media="screen, print" rel="stylesheet" type="text/css">
<link href="vendor/davidstutz/bootstrap-multiselect/dist/css/bootstrap-multiselect.min.css" media="screen, print" rel="stylesheet" type="text/css">
Expand All @@ -12,12 +28,12 @@
<link href="resource/fontawesome/css/regular.css" media="screen, print" rel="stylesheet" type="text/css">
<link href="resource/fontawesome/css/solid.css" media="screen, print" rel="stylesheet" type="text/css">
<link href="resource/css/styles.css" media="screen, print" rel="stylesheet" type="text/css">
{% if ServiceCustomCss %}
<link href="{{ ServiceCustomCss }}" media="screen, print" rel="stylesheet" type="text/css">
{% if GlobalConfig.customCss %}
<link href="{{ GlobalConfig.customCss }}" media="screen, print" rel="stylesheet" type="text/css">
{% endif %}
{% for plugin, files in request.plugins.pluginsCSS %}{% for file in files %}<link href="{{ file }}" media="screen, print" rel="stylesheet" type="text/css">{% endfor %}{% endfor %}

<title>{{ ServiceName }}{% block title %}{% endblock %}</title>
<title>{% block title %}{{ GlobalConfig.serviceNameLong(request.lang) }}{% endblock %}</title>
</head>
<body{% if request.vocabid == '' and request.page != 'feedback' and request.page != 'about' %} class="frontpage-logo"{% else %} class="vocab-{{ request.vocabid }}"{% endif %}>
<noscript>
Expand Down
5 changes: 0 additions & 5 deletions view/meta.twig

This file was deleted.

Loading
Loading