/** * {@inheritDoc} */ public function synchronize(array $documents) { if ($this->clearOnSync) { $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); } } $this->index->clearIndex(); $this->index->addObjects($documents); }
/** * Index a given document in Algolia * * @param string $version * @param string $path */ public function indexDocument($version, $path) { $markdown = Documentation::replaceLinks($version, $this->files->get($path)); $slug = basename($path, '.md'); $blocs = $this->markdown->getBlocks($markdown); $markup = []; $current_link = $slug; $current_h1 = null; $current_h2 = null; $current_h3 = null; $excludedBlocTypes = ['Code', 'Quote', 'Markup', 'FencedCode']; foreach ($blocs as $bloc) { // If the block type should be excluded, skip it... if (isset($bloc['hidden']) || isset($bloc['type']) && in_array($bloc['type'], $excludedBlocTypes) || $bloc['element']['name'] == 'ul') { continue; } if (isset($bloc['type']) && $bloc['type'] == 'Table') { foreach ($bloc['element']['text'][1]['text'] as $tr) { $markup[] = $this->getObject($tr['text'][1], $version, $current_h1, $current_h2, $current_h3, $current_h4, $current_link); } continue; } if (isset($bloc['type']) && $bloc['type'] == 'List') { foreach ($bloc['element']['text'] as $li) { $li['text'] = $li['text'][0]; $markup[] = $this->getObject($li, $version, $current_h1, $current_h2, $current_h3, $current_h4, $current_link); } continue; } preg_match('/<a name=\\"([^\\"]*)\\">.*<\\/a>/iU', $bloc['element']['text'], $link); if (count($link) > 0) { $current_link = $slug . '#' . $link[1]; } else { $markup[] = $this->getObject($bloc['element'], $version, $current_h1, $current_h2, $current_h3, $current_h4, $current_link); } } $this->index->addObjects($markup); echo "Indexed {$version}.{$slug}" . PHP_EOL; }