From 4d4fdb7d954dd3e86705b38ccfe2b9ebd1b429c4 Mon Sep 17 00:00:00 2001 From: Cristan Meijer Date: Tue, 11 Feb 2025 23:22:29 +0100 Subject: [PATCH] Try out clickbaity titles for the details page I don't like it, but my site can't do any good when it can't be found on Google, and it isn't pushed on Google when nobody clicks on it. https://github.com/cristan/unlocode.info/issues/3 --- details/detailsLoader.php | 17 ++++++++++++++--- home/sitemapinclude.php | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/details/detailsLoader.php b/details/detailsLoader.php index 820c698..30cd7c0 100644 --- a/details/detailsLoader.php +++ b/details/detailsLoader.php @@ -130,6 +130,10 @@ public static function vincentyGreatCircleDistance($latitudeFrom, $longitudeFrom return $angle * $earthRadius; } + private function isSearchEngineBot() { + return preg_match('/googlebot|bingbot|slurp|duckduckbot|baiduspider|yandexbot|sogou|exabot/i', $_SERVER['HTTP_USER_AGENT']); + } + private function enrich($country, $location, $connection, $locationFromDb) { $name = $locationFromDb['name']; @@ -140,11 +144,19 @@ private function enrich($country, $location, $connection, $locationFromDb) $toReturn = new stdClass(); $unlocode = $country.$location; - if ($subdivision) { + + if ($this->isSearchEngineBot()) { + $toReturn->title = "UN/LOCODE {$unlocode}: Its location, region, coordinates and more"; + } else if ($subdivision) { $toReturn->title = "{$unlocode}: {$name} - {$subdivision} - {$countryName} | UN/LOCODE info"; + } else { + $toReturn->title = "{$unlocode}: {$name} - {$countryName} | UN/LOCODE info"; + } + $toReturn->description = "Need to identify the UN/LOCODE {$unlocode}? Discover its location here."; + + if ($subdivision) { $toReturn->header = "{$country}{$location}: {$name} - {$subdivision}"; } else { - $toReturn->title = "{$unlocode}: {$name} - {$countryName}"; $toReturn->header = "{$country}{$location}: {$name}"; } @@ -165,7 +177,6 @@ private function enrich($country, $location, $connection, $locationFromDb) $toReturn->regionType = $region['type'] ?? 'Region'; $toReturn->regionName = $region['name'] ?? null; } - $toReturn->description = "Details for UNLOCODE {$unlocode}: {$name} in ".($toReturn->regionName ?? $subdivision).", {$toReturn->country}. Discover functions, coordinates and more."; // Coordinates $coordinates = $locationFromDb['coordinates']; diff --git a/home/sitemapinclude.php b/home/sitemapinclude.php index 0a3a566..2ff3080 100644 --- a/home/sitemapinclude.php +++ b/home/sitemapinclude.php @@ -3,6 +3,6 @@ // lastmod format is YYYY-MM-DD $homeLastMod = '2025-02-03'; $countryLastMod = '2025-02-03'; -$unlocodeLastMod = '2025-02-03'; +$unlocodeLastMod = '2025-02-11'; $numResultsPerSitemap = 1000;