|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Docsets; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Wa72\HtmlPageDom\HtmlPageCrawler; |
|
8
|
|
|
use Illuminate\Support\Facades\Storage; |
|
9
|
|
|
|
|
10
|
|
|
class Jigsaw extends BaseDocset |
|
11
|
|
|
{ |
|
12
|
|
|
public const CODE = 'jigsaw'; |
|
13
|
|
|
public const NAME = 'Jigsaw'; |
|
14
|
|
|
public const URL = 'jigsaw.tighten.co'; |
|
15
|
|
|
public const INDEX = 'docs/installation.html'; |
|
16
|
|
|
public const PLAYGROUND = ''; |
|
17
|
|
|
public const ICON_16 = '../../icons/icon.png'; |
|
18
|
|
|
public const ICON_32 = '../../icons/[email protected]'; |
|
19
|
|
|
public const EXTERNAL_DOMAINS = [ |
|
20
|
|
|
'googleapis.com', |
|
21
|
|
|
'typekit.net', |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function entries(string $file): Collection |
|
26
|
1 |
|
{ |
|
27
|
|
|
$crawler = HtmlPageCrawler::create(Storage::get($file)); |
|
28
|
1 |
|
|
|
29
|
|
|
$entries = collect(); |
|
30
|
1 |
|
$entries = $entries->merge($this->guideEntries($crawler, $file)); |
|
31
|
1 |
|
$entries = $entries->merge($this->sectionEntries($crawler, $file)); |
|
32
|
1 |
|
|
|
33
|
|
|
return $entries; |
|
34
|
1 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function guideEntries(HtmlPageCrawler $crawler, string $file) |
|
37
|
1 |
|
{ |
|
38
|
|
|
$entries = collect(); |
|
39
|
1 |
|
|
|
40
|
|
|
$crawler->filter('h2')->each(function (HtmlPageCrawler $node) use ($entries, $file) { |
|
41
|
|
|
if (basename($file) !== 'index.html') { |
|
42
|
1 |
|
$entries->push([ |
|
43
|
1 |
|
'name' => trim($node->text()), |
|
44
|
1 |
|
'type' => 'Guide', |
|
45
|
1 |
|
'path' => Str::after($file . '#' . Str::slug($node->text()), $this->innerDirectory()), |
|
46
|
1 |
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
}); |
|
49
|
1 |
|
|
|
50
|
|
|
return $entries; |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function sectionEntries(HtmlPageCrawler $crawler, string $file) |
|
54
|
1 |
|
{ |
|
55
|
|
|
$entries = collect(); |
|
56
|
1 |
|
|
|
57
|
|
|
$crawler->filter('h3')->each(function (HtmlPageCrawler $node) use ($entries, $file) { |
|
58
|
|
|
if (basename($file) !== 'index.html') { |
|
59
|
1 |
|
$entries->push([ |
|
60
|
1 |
|
'name' => trim($node->text()), |
|
61
|
1 |
|
'type' => 'Section', |
|
62
|
1 |
|
'path' => Str::after($file . '#' . Str::slug($node->text()), $this->innerDirectory()), |
|
63
|
1 |
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
}); |
|
66
|
1 |
|
|
|
67
|
|
|
return $entries; |
|
68
|
1 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function format(string $html): string |
|
71
|
1 |
|
{ |
|
72
|
|
|
$crawler = HtmlPageCrawler::create($html); |
|
73
|
1 |
|
|
|
74
|
|
|
$this->removeLeftSidebar($crawler); |
|
75
|
1 |
|
$this->removeRightSidebar($crawler); |
|
76
|
1 |
|
$this->removeHeader($crawler); |
|
77
|
1 |
|
$this->removeFooter($crawler); |
|
78
|
1 |
|
$this->updateTopPadding($crawler); |
|
79
|
1 |
|
$this->updateContainer($crawler); |
|
80
|
1 |
|
$this->updateTextSize($crawler); |
|
81
|
1 |
|
$this->updateH4Padding($crawler); |
|
82
|
1 |
|
$this->removeUnwantedCSS($crawler); |
|
83
|
1 |
|
$this->removeUnwantedJavaScript($crawler); |
|
84
|
1 |
|
$this->insertDashTableOfContents($crawler); |
|
85
|
|
|
|
|
86
|
1 |
|
return $crawler->saveHTML(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
protected function removeLeftSidebar(HtmlPageCrawler $crawler) |
|
90
|
|
|
{ |
|
91
|
1 |
|
$crawler->filterXPath('//main[@id="vue-app"]//navigation')->remove(); |
|
92
|
1 |
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
protected function removeRightSidebar(HtmlPageCrawler $crawler) |
|
95
|
|
|
{ |
|
96
|
1 |
|
$crawler->filterXPath('//main[@id="vue-app"]//navigation-on-page')->remove(); |
|
97
|
1 |
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
protected function removeHeader(HtmlPageCrawler $crawler) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$crawler->filter('#vue-app > div:first-child')->remove(); |
|
102
|
1 |
|
$crawler->filter('#vue-app > header')->remove(); |
|
103
|
1 |
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
protected function removeFooter(HtmlPageCrawler $crawler) |
|
106
|
|
|
{ |
|
107
|
1 |
|
$crawler->filter('footer')->remove(); |
|
108
|
1 |
|
} |
|
109
|
|
|
|
|
110
|
1 |
|
protected function updateTopPadding(HtmlPageCrawler $crawler) |
|
111
|
|
|
{ |
|
112
|
1 |
|
$crawler->filter('#vue-app > div > div > div') |
|
113
|
1 |
|
->removeClass('pt-4') |
|
114
|
1 |
|
->css('margin-top', '-1.5rem') |
|
115
|
|
|
; |
|
116
|
1 |
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
protected function updateContainer(HtmlPageCrawler $crawler) |
|
119
|
|
|
{ |
|
120
|
1 |
|
$crawler->filter('#vue-app > div') |
|
121
|
1 |
|
->removeClass('pt-16') |
|
122
|
1 |
|
->removeClass('md:pt-24') |
|
123
|
1 |
|
->removeClass('lg:pt-32') |
|
124
|
1 |
|
->removeClass('md:px-6') |
|
125
|
|
|
; |
|
126
|
|
|
|
|
127
|
1 |
|
$crawler->filter('#vue-app > div > div') |
|
128
|
1 |
|
->removeClass('max-w-3xl') |
|
129
|
|
|
; |
|
130
|
|
|
|
|
131
|
1 |
|
$crawler->filter('div.markdown') |
|
132
|
1 |
|
->removeClass('lg:max-w-md') |
|
133
|
1 |
|
->removeClass('xl:max-w-lg') |
|
134
|
1 |
|
->removeClass('md:mb-6') |
|
135
|
1 |
|
->removeClass('lg:mb-10') |
|
136
|
1 |
|
->removeClass('xl:px-10') |
|
137
|
1 |
|
->removeClass('sm:shadow') |
|
138
|
1 |
|
->removeClass('md:rounded-lg') |
|
139
|
|
|
; |
|
140
|
1 |
|
} |
|
141
|
|
|
|
|
142
|
1 |
|
protected function updateTextSize(HtmlPageCrawler $crawler) |
|
143
|
|
|
{ |
|
144
|
1 |
|
$crawler->filter('h2') |
|
145
|
1 |
|
->addClass('text-3xl') |
|
146
|
|
|
; |
|
147
|
|
|
|
|
148
|
1 |
|
$crawler->filter('h3') |
|
149
|
1 |
|
->css('font-size', '1.5rem') |
|
150
|
|
|
; |
|
151
|
1 |
|
} |
|
152
|
|
|
|
|
153
|
1 |
|
protected function updateH4Padding(HtmlPageCrawler $crawler) |
|
154
|
|
|
{ |
|
155
|
1 |
|
$crawler->filter('h4') |
|
156
|
1 |
|
->css('margin-top', '2.5rem') |
|
157
|
|
|
; |
|
158
|
1 |
|
} |
|
159
|
|
|
|
|
160
|
1 |
|
protected function removeUnwantedCSS(HtmlPageCrawler $crawler) |
|
161
|
|
|
{ |
|
162
|
1 |
|
$crawler->filter('link[href*="docsearch.min.css"]')->remove(); |
|
163
|
1 |
|
} |
|
164
|
1 |
|
|
|
165
|
|
|
protected function removeUnwantedJavaScript(HtmlPageCrawler $crawler) |
|
166
|
1 |
|
{ |
|
167
|
|
|
$crawler->filter('script[src*=docsearch]')->remove(); |
|
168
|
1 |
|
$crawler->filterXPath("//script[text()[contains(.,'docsearch')]]")->remove(); |
|
169
|
1 |
|
} |
|
170
|
|
|
|
|
171
|
|
|
protected function insertDashTableOfContents(HtmlPageCrawler $crawler) |
|
172
|
1 |
|
{ |
|
173
|
1 |
|
$crawler->filter('h2') |
|
174
|
|
|
->before('<a name="//apple_ref/cpp/Section/Top" class="dashAnchor"></a>'); |
|
175
|
1 |
|
|
|
176
|
1 |
|
$crawler->filter('h3')->each(static function (HtmlPageCrawler $node) { |
|
177
|
|
|
$node->before( |
|
178
|
|
|
'<a id="' . Str::slug($node->text()) . '" name="//apple_ref/cpp/Section/' . rawurlencode($node->text()) . '" class="dashAnchor"></a>' |
|
179
|
|
|
); |
|
180
|
|
|
}); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|