Esempio n. 1
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>");
 }
Esempio n. 2
0
 /**
  * Load and parse content from file.
  *
  * @param  SplFileInfo $file
  * @return void
  */
 protected function load(SplFileInfo $file)
 {
     // File info
     $this->filename = $file->getBasename();
     $this->sourcePath = $file->getRelativePath();
     // Load the file
     $data = $file->getContents();
     list($content, $meta) = $this->splitContentMeta($data);
     // Parse meta
     $meta = Yaml::parse($meta) ?: [];
     // Parse content
     switch ($file->getExtension()) {
         case 'md':
         case 'markdown':
             $content = Markdown::parse($content);
             $this->type = self::TYPE_MARKDOWN;
             break;
         case 'tx':
         case 'textile':
             $content = Textile::parse($content);
             $this->type = self::TYPE_TEXTILE;
             break;
     }
     // Set content
     $this->content = $content;
     $this->meta = $meta;
     // Ensure local URLs are absolute
     foreach ($this->meta as $key => $value) {
         if (preg_match('/\\burl\\b|.*_url\\b/', $key)) {
             $this->meta[$key] = $this->builder->getUrl($value);
         }
     }
     // Set target
     $this->setTarget($file);
     // Pagination enabled
     $this->paginate = isset($this->meta['paginate']);
     // Get parent page
     if ($root = dirname(dirname($this->target))) {
         if ($root !== DIRECTORY_SEPARATOR) {
             $this->parentId = ltrim($root, '/');
         }
     }
     // Set URL
     $this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');
     // Remove "index.html" from the end, this provides a cleaner URL
     if (substr($this->url, -10) === 'index.html') {
         $this->url = substr($this->url, 0, -10);
     }
     // Set basic values
     $this->id = trim($this->url, '/') ?: 'root';
     $this->title = $this->get('title');
     $this->url = $this->builder->getUrl($this->url);
     // Set Description
     if ($this->has('description')) {
         $this->description = $this->get('description');
     } else {
         $this->description = $this->getDescription();
     }
 }