Unify domain names in README
[stouyapi.git] / bin / build-html.php
index 18e25e53bb95b2a413bf87110cb20a32653362be..5f601bf57cb892fd736e68111255bc84ee3c419c 100755 (executable)
@@ -31,7 +31,7 @@ foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) {
     $htmlFile = basename($gameDataFile, '.json') . '.htm';
     file_put_contents(
         $wwwGameDir . $htmlFile,
-        renderGameFile($gameDataFile)
+        renderGameFile($gameDataFile, 'game/' . $htmlFile)
     );
 }
 
@@ -42,17 +42,17 @@ foreach (glob($discoverDir . '*.json') as $discoverFile) {
     }
     file_put_contents(
         $wwwDiscoverDir . $htmlFile,
-        renderDiscoverFile($discoverFile)
+        renderDiscoverFile($discoverFile, 'discover/' . $htmlFile)
     );
 }
 
 file_put_contents(
     $wwwDiscoverDir . 'allgames.htm',
-    renderAllGamesList(glob($gameDetailsDir . '*.json'))
+    renderAllGamesList(glob($gameDetailsDir . '*.json'), 'discover/allgames.htm')
 );
 
 
-function renderAllGamesList($detailsFiles)
+function renderAllGamesList($detailsFiles, $path)
 {
     $games = [];
     foreach ($detailsFiles as $gameDataFile) {
@@ -62,6 +62,7 @@ function renderAllGamesList($detailsFiles)
             'title'        => $json->title,
             'genres'       => $json->genres,
             'developer'    => $json->developer->name,
+            'developerUrl' => $json->stouyapi->{'developer-url'} ?? null,
             'suggestedAge' => $json->suggestedAge,
             'apkVersion'   => $json->version->number,
             'apkTimestamp' => $json->version->publishedAt,
@@ -76,6 +77,7 @@ function renderAllGamesList($detailsFiles)
     $navLinks = [
         './' => 'back',
     ];
+    $canonicalUrl = $GLOBALS['baseUrl'] . $path;
 
     $allGamesTemplate = __DIR__ . '/../data/templates/allgames.tpl.php';
     ob_start();
@@ -86,11 +88,13 @@ function renderAllGamesList($detailsFiles)
     return $html;
 }
 
-function renderDiscoverFile($discoverFile)
+function renderDiscoverFile($discoverFile, $path)
 {
     $json = json_decode(file_get_contents($discoverFile));
 
     $title    = $json->title . ' OUYA games';
+    $subtitle = $json->stouyapi->subtitle ?? null;
+
     $sections = [];
     foreach ($json->rows as $row) {
         $section = (object) [
@@ -137,6 +141,11 @@ function renderDiscoverFile($discoverFile)
         $navLinks['./'] = 'discover';
     }
 
+    if ($path === 'discover/index.htm') {
+        $path = 'discover/';
+    }
+    $canonicalUrl = $GLOBALS['baseUrl'] . $path;
+
     $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
     ob_start();
     include $discoverTemplate;
@@ -146,7 +155,7 @@ function renderDiscoverFile($discoverFile)
     return $html;
 }
 
-function renderGameFile($gameDataFile)
+function renderGameFile($gameDataFile, $path)
 {
     $json = json_decode(file_get_contents($gameDataFile));
 
@@ -166,8 +175,18 @@ function renderGameFile($gameDataFile)
         $apkDownloadUrl = null;
     }
     */
+    $developerDetailsUrl = null;
+    if (isset($json->developer->url) && $json->developer->url) {
+        $developerDetailsUrl = '../discover/' . str_replace(
+            'ouya://launcher/discover/',
+            '',
+            $json->developer->url
+        ) . '.htm';
+    }
 
     $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null;
+    $developerUrl       = $json->stouyapi->{'developer-url'} ?? null;
+    $canonicalUrl       = $GLOBALS['baseUrl'] . $path;
 
     $pushUrl = $GLOBALS['pushToMyOuyaUrl']
         . '?game=' . urlencode($json->apk->package);