public function beforeRun(SourceSetEvent $sourceSetEvent) { $finderFactory = new FinderFactory(); $files = $finderFactory->createFinder()->files()->ignoreVCS(true)->ignoreDotFiles(false)->followLinks()->in("./source"); foreach ($files as $file) { $fileName = $file->getRelativePathname(); $pathSegments = explode('/', $fileName); if (empty($pathSegments)) { continue; } $shifted = array_shift($pathSegments); $target = $this->findPathTarget($shifted); if (is_null($target)) { continue; } $templateName = array_pop($pathSegments); $items = array('name' => $templateName, 'file' => $fileName, 'path' => $pathSegments); $this->addListItem($this->listitems, $target, $items); echo $file->getRelativePathname() . "\n"; } // if ($source->isGenerated() || ! $source->canBeFormatted()) { // // Skip generated and inappropriate sources. // continue; // } $sourceSet = $sourceSetEvent->sourceSet(); $this->setListItems($sourceSet); }
public function beforeRun(SourceSetEvent $sourceSetEvent) { $sourceSet = $sourceSetEvent->sourceSet(); foreach ($sourceSet->updatedSources() as $source) { if ($source->isGenerated()) { // Skip generated sources. continue; } if (!$source->data()->get('redirect')) { // Skip source that do not have redirect. continue; } foreach ($source->data()->get('redirect') as $key => $redirect) { // Clone current search with new sourceId. $generatedSource = $source->duplicate($source->sourceId() . ':' . $redirect); // Set destination is original source. $generatedSource->data()->set('destination', $source); // Overwrite permalink. $generatedSource->data()->set('permalink', $redirect); // Add redirect. $generatedSource->data()->set('layout', 'redirect'); // Make sure Sculpin knows this source is generated. $generatedSource->setIsGenerated(); // Add the generated source to the source set. $sourceSet->mergeSource($generatedSource); } } }
/** * @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())); } } }
/** * Before run * * @param SourceSetEvent $sourceSetEvent Source Set Event */ public function beforeRun(SourceSetEvent $sourceSetEvent) { foreach ($sourceSetEvent->updatedSources() as $source) { foreach ($this->extensions as $extension) { if (fnmatch("*.{$extension}", $source->filename())) { $source->data()->append('converters', SculpinTextileBundle::CONVERTER_NAME); break; } } } }
/** * Before run * * @param SourceSetEvent $sourceSetEvent Source Set Event */ public function onSculpinCoreBeforerun(SourceSetEvent $sourceSetEvent) { /** @var FileSource $source */ foreach ($sourceSetEvent->updatedSources() as $source) { foreach ($this->extensions as $extension) { if (fnmatch("*.{$extension}", $source->filename())) { $source->data()->append('converters', SculpinCommonMarkBundle::CONVERTER_NAME); break; } } } }
/** * 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); }
public function beforeRun(SourceSetEvent $sourceSetEvent) { $sourceSet = $sourceSetEvent->sourceSet(); $updatedSources = $sourceSet->updatedSources(); $allSources = $sourceSet->allSources(); $tagsMap = array(); // Build a map of all the tags on each source foreach ($updatedSources as $source) { // Get the tags of this source. if ($sourceTags = $source->data()->get('tags')) { foreach ($sourceTags as $tag) { $tagsMap[$tag][] = $source->sourceId(); } } if ($source->isGenerated()) { // Skip generated sources. continue; } } // Re-run through each source, identifying sources with matching tags. foreach ($updatedSources as $source) { $tagMatch = array(); if ($sourceTags = $source->data()->get('tags')) { // for each tag that this post has... foreach ($sourceTags as $tag) { // get the mapped sources for this tag $tagMatch = array_merge($tagMatch, $tagsMap[$tag]); } $tagMatchCount = array_count_values($tagMatch); // remove self from list of related sources unset($tagMatchCount[$source->sourceid()]); asort($tagMatchCount); // Get information about the matching tags $relatedSources = array(); foreach ($tagMatchCount as $match => $count) { // @TODO - make limit configurable if (count($relatedSources) == 5) { break; } $relatedSource = $allSources[$match]; if (!$relatedSource->data()->get('draft')) { $relatedSources[] = array('title' => $relatedSource->data()->get('title'), 'source' => $relatedSource); } } $source->data()->set('related', $relatedSources); } } }
/** * @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); }
/** * Before run * * @param SourceSetEvent $sourceSetEvent Source Set Event */ public function beforeRun(SourceSetEvent $sourceSetEvent) { $sourceSet = $sourceSetEvent->sourceSet(); /** @var FileSource $source */ foreach ($sourceSetEvent->updatedSources() as $source) { if (!$this->shouldBeConverted($source)) { continue; } $source->setShouldBeSkipped(); $css = $this->parseLess($source->file()->getPathname()); if (!$css) { continue; } $generatedSource = $this->createDuplicate($source); $generatedSource->setContent($css); $sourceSet->mergeSource($generatedSource); } }
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()); } }
public function beforeRun(SourceSetEvent $sourceSetEvent) { if ($sourceSetEvent->sourceSet()->newSources()) { $this->cachedCacheKey = array(); $this->cachedCacheKeyExtension = array(); $this->cachedCacheKeyException = array(); } }
/** * Before run * * @param SourceSetEvent $sourceSetEvent Source Set Event */ public function beforeRun(SourceSetEvent $sourceSetEvent) { if ($sourceSetEvent->updatedSources()) { $this->twig->clearTemplateCache(); } }