![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/vendor/binarytorch/larecipe/src/Traits/ |
<?php namespace BinaryTorch\LaRecipe\Traits; use Symfony\Component\DomCrawler\Crawler; trait Indexable { /** * @param $version * @return mixed */ public function index($version) { return $this->cache->remember(function () use ($version) { $pages = $this->getPages($version); $result = []; foreach($pages as $page) { $split = explode("{{version}}", $page); if (count($split) <= 1) continue; $page = $split[1]; $pageContent = $this->get($version, $page); if(! $pageContent) continue; $indexableNodes = implode(',', config('larecipe.search.engines.internal.index')); $nodes = (new Crawler($pageContent)) ->filter($indexableNodes) ->each(function (Crawler $node, $i) { return $node->text(); }); $title = (new Crawler($pageContent)) ->filter('h1') ->each(function (Crawler $node, $i) { return $node->text(); }); $result[] = [ 'path' => $page, 'title' => $title ? $title[0] : '', 'headings' => $nodes ]; } return $result; }, 'larecipe.docs.'.$version.'.search'); } /** * @param $version * @return mixed */ protected function getPages($version) { $path = base_path(config('larecipe.docs.path').'/'.$version.'/index.md'); // match all markdown urls => [title](url) preg_match_all('/\[.+\]\((.+)\)/', $this->files->get($path), $matches); return $matches[1]; } }