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