|
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 Alpinejs extends BaseDocset |
|
12
|
|
|
{ |
|
13
|
|
|
public const CODE = 'alpinejs'; |
|
14
|
|
|
public const NAME = 'AlpineJS'; |
|
15
|
|
|
public const URL = 'github.com'; |
|
16
|
|
|
public const INDEX = 'alpinejs/alpine.html'; |
|
17
|
|
|
public const PLAYGROUND = 'https://alpinejs.codewithhugo.com/?type=components'; |
|
18
|
|
|
public const ICON_16 = '../../icons/icon.png'; |
|
19
|
|
|
public const ICON_32 = '../../icons/[email protected]'; |
|
20
|
|
|
public const EXTERNAL_DOMAINS = [ |
|
21
|
|
|
'githubassets.com', |
|
22
|
|
|
'githubusercontent.com', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
public function grab(): bool |
|
27
|
|
|
{ |
|
28
|
|
|
$toIgnore = implode('|', [ |
|
29
|
|
|
'/blame', |
|
30
|
|
|
'/blob', |
|
31
|
|
|
]); |
|
32
|
|
|
|
|
33
|
|
|
$toGet = implode('|', [ |
|
34
|
|
|
'.*\.githubassets\.com', |
|
35
|
|
|
'.*\.githubusercontent\.com', |
|
36
|
|
|
'\.css', |
|
37
|
|
|
'\.ico', |
|
38
|
|
|
'\.js', |
|
39
|
|
|
'\.png', |
|
40
|
|
|
'\.svg', |
|
41
|
|
|
'/css', |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
system( |
|
45
|
|
|
"echo; wget github.com/alpinejs/alpine \ |
|
46
|
|
|
--mirror \ |
|
47
|
|
|
--trust-server-names \ |
|
48
|
|
|
--reject-regex='{$toIgnore}' \ |
|
49
|
|
|
--accept-regex='{$toGet}' \ |
|
50
|
|
|
--ignore-case \ |
|
51
|
|
|
--page-requisites \ |
|
52
|
|
|
--adjust-extension \ |
|
53
|
|
|
--convert-links \ |
|
54
|
|
|
--span-hosts \ |
|
55
|
|
|
--domains={$this->externalDomains()} \ |
|
56
|
|
|
--directory-prefix=storage/{$this->downloadedDirectory()} \ |
|
57
|
|
|
-e robots=off \ |
|
58
|
|
|
--quiet \ |
|
59
|
|
|
--show-progress", |
|
60
|
|
|
$result |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
return $result === 0; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
8 |
|
public function entries(string $file): Collection |
|
67
|
|
|
{ |
|
68
|
8 |
|
$crawler = HtmlPageCrawler::create(Storage::get($file)); |
|
69
|
|
|
|
|
70
|
8 |
|
$entries = collect(); |
|
71
|
|
|
|
|
72
|
8 |
|
$entries = $entries->merge($this->guideEntries($crawler, $file)); |
|
73
|
8 |
|
$entries = $entries->merge($this->sectionEntries($crawler, $file)); |
|
74
|
|
|
|
|
75
|
8 |
|
return $entries; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
8 |
|
protected function guideEntries(HtmlPageCrawler $crawler, string $file) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
8 |
|
$entries = collect(); |
|
81
|
|
|
|
|
82
|
|
|
$crawler->filter('.entry-content h2')->each(function (HtmlPageCrawler $node) use ($entries) { |
|
83
|
8 |
|
$entries->push([ |
|
84
|
8 |
|
'name' => trim($node->text()), |
|
85
|
8 |
|
'type' => 'Guide', |
|
86
|
8 |
|
'path' => $this->url() . '/alpinejs/' . $node->children('a')->attr('href') |
|
87
|
|
|
]); |
|
88
|
8 |
|
}); |
|
89
|
|
|
|
|
90
|
8 |
|
return $entries; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
8 |
|
protected function sectionEntries(HtmlPageCrawler $crawler, string $file) |
|
94
|
|
|
{ |
|
95
|
8 |
|
$entries = collect(); |
|
96
|
|
|
|
|
97
|
|
|
$crawler->filter('.entry-content h3')->each(function (HtmlPageCrawler $node) use ($entries, $file) { |
|
|
|
|
|
|
98
|
8 |
|
$entries->push([ |
|
99
|
8 |
|
'name' => trim($node->text()), |
|
100
|
8 |
|
'type' => 'Section', |
|
101
|
8 |
|
'path' => $this->url() . '/alpinejs/' . $node->children('a')->attr('href') |
|
102
|
|
|
]); |
|
103
|
8 |
|
}); |
|
104
|
|
|
|
|
105
|
8 |
|
return $entries; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
4 |
|
public function format(string $file): string |
|
109
|
|
|
{ |
|
110
|
4 |
|
$crawler = HtmlPageCrawler::create(Storage::get($file)); |
|
111
|
|
|
|
|
112
|
4 |
|
$this->removeGitHubNavbar($crawler); |
|
113
|
4 |
|
$this->removeRepositoryNavigation($crawler); |
|
114
|
4 |
|
$this->removeSignupPrompt($crawler); |
|
115
|
4 |
|
$this->removeFileNavigation($crawler); |
|
116
|
4 |
|
$this->removeRepositoryDetails($crawler); |
|
117
|
4 |
|
$this->removeRightSidebar($crawler); |
|
118
|
4 |
|
$this->removeWeirdBoxHeader($crawler); |
|
119
|
4 |
|
$this->removeContentBorder($crawler); |
|
120
|
|
|
|
|
121
|
4 |
|
$this->removeFooter($crawler); |
|
122
|
|
|
|
|
123
|
4 |
|
$this->removeCrossOriginAndIntegrity($crawler); |
|
124
|
|
|
|
|
125
|
4 |
|
$this->insertDashTableOfContents($crawler); |
|
126
|
|
|
|
|
127
|
4 |
|
return $crawler->saveHTML(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
4 |
|
protected function removeGitHubNavbar(HtmlPageCrawler $crawler) |
|
131
|
|
|
{ |
|
132
|
4 |
|
$crawler->filter('.js-header-wrapper')->remove(); |
|
133
|
4 |
|
} |
|
134
|
|
|
|
|
135
|
4 |
|
protected function removeRepositoryNavigation(HtmlPageCrawler $crawler) |
|
136
|
|
|
{ |
|
137
|
4 |
|
$crawler->filter('.bg-gray-light.pt-3.hide-full-screen.mb-5')->remove(); |
|
138
|
4 |
|
} |
|
139
|
|
|
|
|
140
|
4 |
|
protected function removeSignupPrompt(HtmlPageCrawler $crawler) |
|
141
|
|
|
{ |
|
142
|
4 |
|
$crawler->filter('signup-prompt')->remove(); |
|
143
|
4 |
|
} |
|
144
|
|
|
|
|
145
|
4 |
|
protected function removeFileNavigation(HtmlPageCrawler $crawler) |
|
146
|
|
|
{ |
|
147
|
4 |
|
$crawler->filter('.file-navigation')->remove(); |
|
148
|
4 |
|
} |
|
149
|
|
|
|
|
150
|
4 |
|
protected function removeRepositoryDetails(HtmlPageCrawler $crawler) |
|
151
|
|
|
{ |
|
152
|
4 |
|
$crawler->filter('.Box.mb-3')->remove(); |
|
153
|
4 |
|
} |
|
154
|
|
|
|
|
155
|
4 |
|
protected function removeRightSidebar(HtmlPageCrawler $crawler) |
|
156
|
|
|
{ |
|
157
|
4 |
|
$crawler->filter('.flex-shrink-0.col-12.col-md-3')->remove(); |
|
158
|
4 |
|
} |
|
159
|
|
|
|
|
160
|
4 |
|
protected function removeWeirdBoxHeader(HtmlPageCrawler $crawler) |
|
161
|
|
|
{ |
|
162
|
4 |
|
$crawler->filter('.Box-header')->remove(); |
|
163
|
4 |
|
} |
|
164
|
|
|
|
|
165
|
4 |
|
protected function removeContentBorder(HtmlPageCrawler $crawler) |
|
166
|
|
|
{ |
|
167
|
4 |
|
$crawler->filter('#readme')->addClass('border-0 !important'); |
|
168
|
4 |
|
} |
|
169
|
|
|
|
|
170
|
4 |
|
protected function removeFooter(HtmlPageCrawler $crawler) |
|
171
|
|
|
{ |
|
172
|
4 |
|
$crawler->filter('.footer')->remove(); |
|
173
|
4 |
|
} |
|
174
|
|
|
|
|
175
|
4 |
|
protected function removeCrossOriginAndIntegrity(HtmlPageCrawler $crawler) |
|
176
|
|
|
{ |
|
177
|
4 |
|
$crawler->filter('script, link') |
|
178
|
4 |
|
->removeAttribute('integrity') |
|
179
|
4 |
|
->removeAttribute('crossorigin'); |
|
180
|
4 |
|
} |
|
181
|
|
|
|
|
182
|
4 |
|
protected function insertDashTableOfContents(HtmlPageCrawler $crawler) |
|
183
|
|
|
{ |
|
184
|
4 |
|
$crawler->filter('head') |
|
185
|
4 |
|
->before('<a name="//apple_ref/cpp/Section/Top" class="dashAnchor"></a>'); |
|
186
|
|
|
|
|
187
|
|
|
$crawler->filter('h3')->each(function (HtmlPageCrawler $node) { |
|
188
|
4 |
|
$node->prepend( |
|
189
|
|
|
'<a id="' |
|
190
|
4 |
|
. Str::slug($node->text()) |
|
191
|
4 |
|
. '" name="//apple_ref/cpp/Section/' |
|
192
|
4 |
|
. rawurlencode($node->text()) |
|
193
|
4 |
|
. '" class="dashAnchor"></a>' |
|
194
|
|
|
); |
|
195
|
4 |
|
}); |
|
196
|
4 |
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.