/**
  * Show a documentation page.
  *
  * @param  string      $doc
  * @param  string|null $version
  * @param  string|null $page
  * @return \Illuminate\Http\Response
  */
 public function show($doc, $version = null, $page = null)
 {
     if (is_null($version)) {
         $version = $this->docs->getDefaultVersion($doc);
         if (is_null($version)) {
             abort(404);
         }
         return redirect()->route('show', [$doc, $version]);
     }
     if (is_null($page)) {
         $page = $this->docs->getDefaultPage($doc, 'installation');
     }
     $content = $this->docs->getContent($doc, $version, $page);
     if (is_null($content)) {
         abort(404);
     }
     $title = (new Crawler($content))->filterXPath('//h1');
     $title = count($title) ? $title->text() : null;
     return view('show', ['toc' => $this->docs->getToc($doc, $version), 'title' => $title, 'content' => $content, 'currentDoc' => $this->docs->all()[$doc], 'currentVersion' => $version, 'docs' => $this->docs->all(), 'versions' => $this->docs->getVersions($doc), 'page' => $page]);
 }
Пример #2
0
 /**
  * Determine if the given URL segment is a valid version.
  *
  * @param  string  $version
  * @return bool
  */
 protected function isVersion($version)
 {
     return in_array($version, array_keys(Documentation::getDocVersions()));
 }
Пример #3
0
 /**
  * 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;
 }
 /**
  * Get the available documentation versions.
  *
  * @return array
  */
 protected function getEnabledVersions()
 {
     return $this->docs->getDocsEnabledVersions();
 }