| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Docsets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Godbout\DashDocsetBuilder\Docsets\BaseDocset; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\Storage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Wa72\HtmlPageDom\HtmlPageCrawler; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class LaravelMix extends BaseDocset | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     public const CODE = 'laravel-mix'; | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     public const NAME = 'Laravel Mix'; | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     public const URL = 'laravel-mix.com'; | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     public const INDEX = 'docs/main/installation.html'; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public const PLAYGROUND = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     public const ICON_16 = 'favicon-16x16.png'; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     public const ICON_32 = 'favicon-32x32.png'; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     public const EXTERNAL_DOMAINS = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function grab(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |          * can't use PCRE regex style, so need to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |          * type the whole list of shit (versions) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |          * to ignore. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $toIgnore = implode('|', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             'cdn-cgi', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             'docs/1.7/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             'docs/2.0/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             'docs/2.1/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'docs/3.0/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'docs/4.0/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'docs/4.1/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'docs/5.0/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'docs/6.0/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         system( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             "echo; wget laravel-mix.com/docs \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 --mirror \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 --trust-server-names \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 --reject-regex='{$toIgnore}' \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 --page-requisites \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 --adjust-extension \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 --convert-links \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 --span-hosts \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 --domains={$this->externalDomains()} \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 --directory-prefix=storage/{$this->downloadedDirectory()} \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 -e robots=off \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 --quiet \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 --show-progress", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |         return $result === 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 16 |  |     public function entries(string $file): Collection | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 16 |  |         $crawler = HtmlPageCrawler::create(Storage::get($file)); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 16 |  |         $entries = collect(); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 16 |  |         $entries = $entries->union($this->guideEntries($crawler, $file)); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 16 |  |         $entries = $entries->union($this->sectionEntries($crawler, $file)); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 16 |  |         return $entries; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 16 |  |     protected function guideEntries(HtmlPageCrawler $crawler, string $file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 16 |  |         $entries = collect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 16 |  |         if (Str::contains($file, "{$this->url()}/docs/main/installation.html")) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 16 |  |             $crawler->filter('nav#nav li a')->each(function (HtmlPageCrawler $node) use ($entries) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 16 |  |                 $entries->push([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 16 |  |                     'name' => trim($node->text()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 16 |  |                     'type' => 'Guide', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 16 |  |                     'path' => $this->url() . '/docs/main/' . $node->attr('href'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 16 |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 | 16 |  |         return $entries; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 16 |  |     protected function sectionEntries(HtmlPageCrawler $crawler, string $file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 16 |  |         $entries = collect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 16 |  |         $crawler->filter('h2, h3')->each(function (HtmlPageCrawler $node) use ($entries, $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 16 |  |             $entries->push([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 16 |  |                 'name' => trim($node->text()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 16 |  |                 'type' => 'Section', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 16 |  |                 'path' => Str::after($file . '#' . Str::slug($node->text()), $this->innerDirectory()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 16 |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 103 | 16 |  |         return $entries; | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 106 | 16 |  |     public function format(string $file): string | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 108 | 16 |  |         $crawler = HtmlPageCrawler::create(Storage::get($file)); | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 110 | 16 |  |         $this->removeHeader($crawler); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 | 16 |  |         $this->removeLeftSidebar($crawler); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 | 16 |  |         $this->removeFooter($crawler); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 | 16 |  |         $this->insertOnlineRedirection($crawler, $file); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         $this->insertDashTableOfContents($crawler); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 | 16 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         return $crawler->saveHTML(); | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 119 | 16 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |     protected function removeHeader(HtmlPageCrawler $crawler) | 
            
                                                                        
                            
            
                                    
            
            
                | 121 | 16 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 122 | 16 |  |         $crawler->filter('header.sticky')->remove(); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 124 | 16 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |     protected function removeLeftSidebar(HtmlPageCrawler $crawler) | 
            
                                                                        
                            
            
                                    
            
            
                | 126 | 16 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 | 16 |  |         $crawler->filter('#nav')->remove(); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 129 | 16 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     protected function removeFooter(HtmlPageCrawler $crawler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 16 |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 132 | 16 |  |         $crawler->filter('footer.flex')->remove(); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 134 | 16 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |     protected function insertOnlineRedirection(HtmlPageCrawler $crawler, string $file) | 
            
                                                                        
                            
            
                                    
            
            
                | 136 | 16 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 137 | 16 |  |         $onlineUrl = Str::substr(Str::after($file, $this->innerDirectory()), 1, -5); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 | 16 |  |         $crawler->filter('html')->prepend("<!-- Online page at https://$onlineUrl -->"); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 | 16 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 141 | 16 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 16 |  |     protected function insertDashTableOfContents(HtmlPageCrawler $crawler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 16 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 16 |  |         $crawler->filter('body') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 16 |  |             ->before('<a name="//apple_ref/cpp/Section/Top" class="dashAnchor"></a>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 16 |  |         $crawler->filter('h2, h3, h4')->each(function (HtmlPageCrawler $node) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 16 |  |             $node->prepend( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                 '<a id="' . Str::slug( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                     $node->text() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                 ) . '" name="//apple_ref/cpp/Section/' . rawurlencode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                     $node->text() | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 153 |  |  |                 ) . '" class="dashAnchor"></a>' | 
            
                                                                        
                                                                
            
                                    
            
            
                | 154 |  |  |             ); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 155 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 157 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 158 |  |  |  |