Skip to content

Commit

Permalink
WEB: Add a description and a descriptive title for OpenGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
lephilousophe committed Sep 6, 2024
1 parent e1c834c commit 6e3acb1
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 3 deletions.
15 changes: 15 additions & 0 deletions include/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,19 @@ protected function getConfigVars($title)
{
return $this->smarty->getConfigVars($title);
}

protected function getHeadline($body)
{
$headline = '';
for ($line = \strtok($body, PHP_EOL); $line !== false; $line = \strtok(PHP_EOL)) {
$line = \strip_tags($line);
$headline .= $line . ' ';
if (\strlen($headline) > 250) {
$headline = substr($headline, 0, 249);
$headline .= "\u{2026}";
break;
}
}
return $headline;
}
}
2 changes: 2 additions & 0 deletions include/Pages/ArticlePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function index($params)
$content = $purifier->purify($Parsedown->text($article->body()));

return $this->renderPage([
'title' => $title,
'description' => htmlentities($this->getHeadline($content)),
'content_title' => $title,
'date' => $date,
'author' => $author,
Expand Down
3 changes: 3 additions & 0 deletions include/Pages/CompatibilityPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function getGame($target, $version)
return $this->renderPage(
array(
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')),
'subtitle' => $game->getGame()->getName(),
'description' => $this->getConfigVars('compatibilityIntro'),
'content_title' => preg_replace(
'/{version}/',
$version,
Expand All @@ -116,6 +118,7 @@ public function getAll($version, $versions)
return $this->renderPage(
[
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')),
'description' => $this->getConfigVars('compatibilityIntro'),
'content_title' => preg_replace(
'/{version}/',
$version,
Expand Down
1 change: 1 addition & 0 deletions include/Pages/DemosPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function index()
return $this->renderPage(
array(
'title' => $this->getConfigVars('demosTitle'),
'description' => $this->getConfigVars('gamesDemosContentP1'),
'content_title' => $this->getConfigVars('demosContentTitle'),
'demos' => $demos,
)
Expand Down
1 change: 1 addition & 0 deletions include/Pages/DirectorDemosPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function index()
return $this->renderPage(
array(
'title' => $this->getConfigVars('directorDemosTitle'),
'description' => $this->getConfigVars('gamesDemosContentP1'),
'content_title' => $this->getConfigVars('directorDemosContentTitle'),
'demos' => $demos,
)
Expand Down
1 change: 1 addition & 0 deletions include/Pages/DownloadsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function index()
return $this->renderPage(
array(
'title' => $this->getConfigVars('downloadsTitle'),
'description' => \strip_tags($this->getConfigVars('downloadsContentP1')),
'content_title' => $this->getConfigVars('downloadsContentTitle'),
'downloads' => $downloads,
'recommendedDownload' => $recommendedDownload
Expand Down
1 change: 1 addition & 0 deletions include/Pages/GamesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function index()
return $this->renderPage(
array(
'title' => $this->getConfigVars('gamesTitle'),
'description' => strip_tags($this->getConfigVars('gamesContentP1')),
'content_title' => $this->getConfigVars('gamesContentTitle'),
'downloads' => $downloads,
)
Expand Down
1 change: 1 addition & 0 deletions include/Pages/LinksPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function index()
return $this->renderPage(
array(
'title' => $this->getConfigVars('linksTitle'),
// TODO: add a description
'content_title' => $this->getConfigVars('linksContentTitle'),
'links' => $links,
)
Expand Down
9 changes: 8 additions & 1 deletion include/Pages/NewsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ public function getNews($filename = null)
{
if ($filename == null) {
$news_items = $this->newsModel->getAllNews();
$filename = 'archive';
$subtitle = null;
$description = $this->getConfigVars('introHeaderContentP1');
} else {
$news_items = array($this->newsModel->getOneByFilename($filename));
$subtitle = $news_items[0]->getTitle();
$description = htmlentities($this->getHeadline($news_items[0]->getContent()));
}

return $this->renderPage(
array(
'title' => $this->getConfigVars('newsTitle'),
'subtitle' => $subtitle,
'description' => $description,
'content_title' => $this->getConfigVars('newsContentTitle'),
'show_intro' => false,
'news_items' => $news_items,
Expand All @@ -69,6 +74,8 @@ public function getNewsIntro()
return $this->renderPage(
array(
'title' => $this->getConfigVars('newsTitle'),
'subtitle' => $this->getConfigVars('newsContentTitle'),
'description' => $this->getConfigVars('introHeaderContentP1'),
'content_title' => $this->getConfigVars('newsContentTitle'),
'show_intro' => true,
'news_items' => $news_items,
Expand Down
5 changes: 5 additions & 0 deletions include/Pages/ScreenshotsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function index($args)
return $this->renderPage(
[
'title' => $this->getConfigVars('screenshotsTitle'),
// TODO: Add a description
'content_title' => $this->getConfigVars('screenshotsContentTitle'),
'screenshots' => $screenshot,
'random_shot' => $random_shot,
Expand All @@ -51,17 +52,21 @@ public function getCategory($category, $game)
{
if (empty($game)) {
$screenshots = $this->screenshotsModel->getScreenshotsByCompanyId($category);
$subtitle = $screenshots['title'];
} else {
$screenshots = [
'category' => $category,
'games' => $this->screenshotsModel->getScreenshotsBySubcategory($game)
];
$subtitle = $screenshots['games'][0]->getName();
}
$this->template = 'pages/screenshots_category.tpl';

return $this->renderPage(
[
'title' => $this->getConfigVars('screenshotsTitle'),
// TODO: Add a description
'subtitle' => $subtitle,
'content_title' => $this->getConfigVars('screenshotsContentTitle'),
'screenshots' => $screenshots,
'category' => $category,
Expand Down
1 change: 1 addition & 0 deletions include/Pages/SimplePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function index($data = null)

return $this->renderPage([
'title' => $this->getConfigVars("{$this->key}Title"),
'description' => $this->getConfigVars("{$this->key}Description"),
'content_title' => $this->getConfigVars("{$this->key}ContentTitle"),
'data' => $data
]);
Expand Down
5 changes: 3 additions & 2 deletions templates/pages/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="alternate" type="application/atom+xml" title="{#indexAtomFeed#}" href="{$baseurl|lang}/feeds/atom/">
<link rel="alternate" type="application/rss+xml" title="{#indexRSSFeed#}" href="{$baseurl|lang}/feeds/rss/">
<title>ScummVM :: {$title}</title>
{if isset($description)}<meta name="description" content="{$description}">{/if}
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=oLBEjaJ9ag">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png?v=oLBEjaJ9ag">
Expand All @@ -23,8 +24,8 @@
<!-- OpenGraph -->
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:title" content="ScummVM">
<meta property="og:description" content="ScummVM is a collection of game engines for playing classic graphical RPGs and point-and-click adventure games on modern hardware.">
<meta property="og:title" content="ScummVM :: {$title}{if isset($subtitle)} :: {$subtitle}{/if}">
{if isset($description)}<meta property="og:description" content="{$description}">{/if}
<meta property="og:url" content="{$baseurl|lang}{$pageurl}">
<meta property="og:image" content="https://www.scummvm.org/images/og-image.jpg">
<link rel="canonical" href="{$baseurl|lang}{$pageurl}" />
Expand Down

0 comments on commit 6e3acb1

Please sign in to comment.