$config['DIRECTUS_URL'], ]); try { $posts = $client->getItems($config['DIRECTUS_TABLE']); if (!file_exists('source/_games')) { mkdir('source/_games'); } $slugify = new Slugify(); $tidy = new tidy(); foreach($posts as $post) { if ($post->active !== 1) { // skip drafts or deleted continue; } $filename = 'source/_games/'.$slugify->slugify($post->name).'.md'; $content = str_replace("\r", "", $post->content); $content = $tidy->repairString(trim($content), [ 'show-body-only' => true ]); $page = '---'.PHP_EOL. 'extends: _layouts.post'.PHP_EOL. 'title: '.$post->name.PHP_EOL. 'date: '.$post->created_at.PHP_EOL. 'feature: _'.$post->cover->name.PHP_EOL. '---'.PHP_EOL. $content; download_file( $config['DIRECTUS_URL'].'/'.$config['DIRECTUS_STORAGE'].'/'.$post->cover->name, 'source/_games/_'.$post->cover->name ); $file = fopen($filename, 'w'); fwrite($file, $page); fclose($file); } } catch (Exception $e) { echo $e->getMessage(); } return [ 'baseUrl' => '/', 'production' => true, 'collections' => [ 'games' => [ 'path' => 'game/{filename}', 'sort' => '-date' ] ], 'title' => $config['SITE_TITLE'], // site title 'sitetitle' => $config['SITE_TITLE'], // site title 'description' => "", /** * Helpers start here */ 'normalizeUrl' => function($page, $target) { if ($target === '') { return '/'; } if ($target[0] === '/') { $target = ltrim($target, '/'); } if (strpos($target, 'http:') === FALSE && strpos($target, 'https:') === FALSE) { $target = $page->baseUrl.$target; } return $target; }, 'css' => function($page, $target){ return ''; }, 'js' => function($page, $target) { return ''; }, 'prevnext' => function($page, $previous = '', $next = '', $classname = '') { $out = '
'; return $out; }, 'thumbnail' => function($page, $image, $title, $subtitle) { $slugify = new Slugify(); $imagefile = __DIR__ . '/source/_posts/' . $date . '/' . $image; $outdir = __DIR__ . '/build_local/blog/' . $date . '/' . $slugify->slugify($title); if (!file_exists($outdir)) { mkdir($outdir, 0755, true); } $imagep = Image::make($imagefile); if (!file_exists($outdir.'/_small'.$image)) { $imagep->resize(300, null, function ($constraint) { $constraint->aspectRatio(); })->save($outdir.'/thumb'.$image); } return ''.$title.'
'.$subtitle.'