コード例 #1
0
 /**
  * Register custom events.
  */
 private function registerEvents()
 {
     foreach ($this->getSetting('events', []) as $event => $listeners) {
         foreach ($listeners as $listener) {
             Event::bind($event, $listener);
         }
     }
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get application instance
     $app = $this->getApplication();
     // Set CLI output
     $app->setOutput($output);
     // Initialize builder
     $builder = new Builder($app);
     // Get arguments
     $env = $app->getEnvironment();
     $part = $input->getOption('part');
     $skip = explode(',', preg_replace('/\\s+/', '', $input->getOption('skip')));
     $isProduction = $env === 'production';
     // Set system paths
     $this->target = $app->getTarget();
     // Announce production build
     if ($isProduction) {
         $output->writeln("<info>Building production version...</info>");
     }
     // Remove all built files
     if (empty($skip) && $part === 'all') {
         $output->writeln("<comment>Cleaning target...</comment>");
         $builder->cleanTarget();
     }
     // Create server configuration
     if (in_array('config', $skip) === false && in_array($part, ['all', 'config'])) {
         $output->writeln("<comment>Creating server configuration...</comment>");
         $builder->createServerConfig();
     }
     // Copy static files
     if (in_array('static', $skip) === false && in_array($part, ['all', 'static'])) {
         $output->writeln("<comment>Copying statics...</comment>");
         $builder->copyStaticFiles();
     }
     // Build assets
     if (in_array('assets', $skip) === false && in_array($part, ['all', 'assets'])) {
         $output->writeln("<comment>Building assets (gulp)...</comment>\n");
         $output->writeln(shell_exec("gulp --target={$this->target} --env={$env}"));
         // Fire event
         Event::fire('assets.built');
     }
     // Build pages
     if (in_array('pages', $skip) === false && in_array($part, ['all', 'pages'])) {
         $output->writeln("<comment>Building pages...</comment>");
         $builder->build();
     }
     $output->writeln("<info>Build complete!</info>");
 }
コード例 #3
0
ファイル: Builder.php プロジェクト: torann/skosh-generator
 /**
  * Generate pagination
  *
  * @param  Content $content
  * @return void
  */
 private function paginate(Content $content)
 {
     $maxPerPage = $this->app->getSetting('max_per_page', 15);
     $posts = $this->getPosts($content);
     $slices = [];
     $slice = [];
     $totalItems = 0;
     foreach ($posts as $k => $v) {
         if (count($slice) === $maxPerPage) {
             $slices[] = $slice;
             $slice = [];
         }
         $slice[$k] = $v;
         $totalItems++;
     }
     $slices[] = $slice;
     // Base URL
     $pageRoot = '/' . dirname($content->target);
     // Pagination data
     $pagination = ['total_posts' => count($posts), 'total_pages' => count($slices), 'next' => null, 'prev' => null];
     $pageNumber = 0;
     foreach ($slices as $slice) {
         $pageNumber++;
         // Set page target filename
         $target = $pageNumber > 1 ? "{$pageRoot}/page/{$pageNumber}" : $content->target;
         // Previous page is index
         if ($pageNumber === 2) {
             $pagination['prev'] = $this->getUrl($pageRoot);
         } else {
             if ($pageNumber > 1) {
                 $pagination['prev'] = $this->getUrl("{$pageRoot}/page/" . ($pageNumber - 1));
             } else {
                 $pagination['prev'] = null;
             }
         }
         // Set next page
         if ($pageNumber + 1 <= $pagination['total_pages']) {
             $pagination['next'] = $this->getUrl("{$pageRoot}/page/" . ($pageNumber + 1));
         } else {
             $pagination['next'] = null;
         }
         // Set current page
         $pagination['page'] = $pageNumber;
         // Set page URL
         $content->url = $pageNumber > 1 ? $this->getUrl(dirname($target)) : $content->url;
         // Render content
         $html = $this->twig->render($content->id, ['page' => $content, 'posts' => $slice, 'pagination' => $pagination, 'parent' => $this->getParent($content->parentId)]);
         // Fire event
         Event::fire('paginate.before', [$this, &$target, &$html]);
         // Save Content
         $this->savePage($target, $html);
     }
 }