$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 '
'. $page->img($image, $title). '

'.$title.'
'.$subtitle.'

'. '
'; }, 'imgurl' => function($page, $url) { return $page->baseUrl.$config['IMAGE_DIR']."/".ltrim($url, '/'); }, 'img' => function($page, $url, $title) { return ''.$title.''; }, 'url' => function($page, $url) { return $page->normalizeUrl($url); }, 'firstwords' => function($page, $text, $limit = 20) { $text = preg_replace('/\s+/', ' ', trim($text)); $words = explode(" ", $text); // an array // if number of words you want to get is greater than number of words in the string if ($limit > count($words)) { // then use number of words in the string $limit = count($words); } $new_string = ""; for ($i = 0; $i < $limit; $i++) { $new_string .= $words[$i] . " "; } $tidy = new tidy(); return $tidy->repairString(trim($new_string), [ 'show-body-only' => true ]); }, 'navitem' => function($page, $url, $title) { $class = ''; $sr = ''; if ($page->getPath() === $url) { $class=' active'; $sr = ' (текущая)'; } return ''; } ];