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); } } }
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); } } }
/** * 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 beforeRun(SourceSetEvent $sourceSetEvent) { if ($sourceSetEvent->sourceSet()->newSources()) { $this->cachedCacheKey = array(); $this->cachedCacheKeyExtension = array(); $this->cachedCacheKeyException = array(); } }