| 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 ChartjsPluginDatalabels extends BaseDocset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public const CODE = 'chartjs-plugin-datalabels'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public const NAME = 'chartjs-plugin-datalabels'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public const URL = 'chartjs-plugin-datalabels.netlify.app'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public const INDEX = 'guide/index.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public const PLAYGROUND = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public const ICON_16 = '../../icons/icon.png'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public const ICON_32 = '../../icons/[email protected]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public const EXTERNAL_DOMAINS = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 8 |  |     public function entries(string $file): Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 8 |  |         $crawler = HtmlPageCrawler::create(Storage::get($file)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 8 |  |         $entries = collect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 8 |  |         $entries = $entries->merge($this->guideEntries($crawler, $file)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 8 |  |         $entries = $entries->merge($this->sectionEntries($crawler, $file)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 8 |  |         return $entries; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 8 |  |     protected function guideEntries(HtmlPageCrawler $crawler, string $file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 8 |  |         $entries = collect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 8 |  |         if (Str::contains($file, "{$this->url()}/guide/index.html")) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $crawler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 8 |  |                 ->filter('.sidebar-links > li > a') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 8 |  |                 ->each(function (HtmlPageCrawler $node) use ($entries) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 8 |  |                     $entries->push([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 8 |  |                         'name' => $node->text(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 8 |  |                         'type' => 'Guide', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 8 |  |                         'path' => $this->url() . '/guide/' . $node->attr('href'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 8 |  |                 }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 8 |  |         return $entries; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 8 |  |     protected function sectionEntries(HtmlPageCrawler $crawler, string $file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 8 |  |         $entries = collect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 8 |  |         $crawler->filter('h2')->each(function (HtmlPageCrawler $node) use ($entries, $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 8 |  |             $entries->push([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 8 |  |                 'name' => $node->text(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 8 |  |                 'type' => 'Section', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 8 |  |                 'path' => Str::after($file . '#' . Str::slug($node->text()), $this->innerDirectory()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 8 |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 8 |  |         return $entries; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 4 |  |     public function format(string $file): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 4 |  |         $crawler = HtmlPageCrawler::create(Storage::get($file)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 4 |  |         $this->removeLeftSidebar($crawler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 4 |  |         $this->removeHeaderContentExceptSamples($crawler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 4 |  |         $this->removeEditLink($crawler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 4 |  |         return $crawler->saveHTML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 4 |  |     protected function removeLeftSidebar(HtmlPageCrawler $crawler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 4 |  |         $crawler->filter('.sidebar')->remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 4 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 4 |  |     protected function removeHeaderContentExceptSamples(HtmlPageCrawler $crawler) | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 | 4 |  |         $header = $crawler->filter('header'); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 4 |  |         $header->filter('header > *:not(:last-child)')->remove(); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 | 4 |  |         $header->filter('header form')->remove(); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 4 |  |         $header->filter('header .nav-item:not(:nth-child(3))')->remove(); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 4 |  |         $header->filter('header nav > a')->remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 4 |  |     protected function removeEditLink(HtmlPageCrawler $crawler) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 4 |  |         $crawler->filter('.edit-link')->remove(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 4 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |  |