/**
  * @param Parser $parser
  * @param SourceSetEvent $event
  */
 protected function compress(Parser $parser, SourceSetEvent $event)
 {
     foreach ($event->allSources() as $source) {
         $ext = explode('.', $source->filename());
         $ext = $ext[count($ext) - 1];
         if (in_array($ext, ['html', 'md', 'markdown'])) {
             $source->setFormattedContent($parser->compress($source->formattedContent()));
         }
     }
 }
 /**
  * Index on after run event
  *
  * @param \Sculpin\Core\Event\SourceSetEvent $event
  */
 public function afterRun(SourceSetEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     $documents = array();
     foreach ($event->allSources() as $item) {
         if ($item->data()->get('indexed')) {
             $documents[] = $this->documentBuilder->build($item);
         }
     }
     $this->searchEngine->synchronize($documents);
 }
 /**
  * @param \Sculpin\Core\Event\SourceSetEvent $event
  */
 public function afterRun(SourceSetEvent $event)
 {
     $documents = array();
     /** @var AbstractSource $item */
     foreach ($event->allSources() as $item) {
         if ($item->data()->get('indexed')) {
             if ($item->isGenerated()) {
                 continue;
             }
             $documents[] = $this->parseSource($item);
         }
     }
     $this->index->clearIndex();
     $this->index->addObjects($documents);
 }
 /**
  * @param \Sculpin\Core\Event\SourceSetEvent $event
  */
 public function afterRun(SourceSetEvent $event)
 {
     $documents = array();
     /** @var AbstractSource $item */
     foreach ($event->allSources() as $item) {
         if ($item->data()->get('indexed')) {
             if ($item->isGenerated()) {
                 continue;
             }
             $documents[] = $this->parseSource($item);
         }
     }
     $output['entries'] = $documents;
     $json = json_encode($output, JSON_PRETTY_PRINT);
     file_put_contents($this->outputDir . '/index.json', $json);
 }
 public function beforeRunPost(SourceSetEvent $sourceSetEvent)
 {
     $anItemHasChanged = false;
     foreach ($this->collection as $item) {
         if ($item->hasChanged()) {
             $anItemHasChanged = true;
             $this->collection->init();
             break;
         }
     }
     if ($anItemHasChanged) {
         foreach ($sourceSetEvent->allSources() as $source) {
             if ($source->data()->get('use') && in_array($this->dataProviderName, $source->data()->get('use'))) {
                 $source->forceReprocess();
             }
         }
     }
     foreach ($this->collection as $item) {
         $item->data()->set('next_' . $this->dataSingularName, $item->nextItem());
         $item->data()->set('previous_' . $this->dataSingularName, $item->previousItem());
     }
 }